# filename-reserved-regex

> Regular expression for matching reserved filename characters

Latest version **4.0.1** (published 2026-08-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install filename-reserved-regex
pnpm add filename-reserved-regex
yarn add filename-reserved-regex
bun add filename-reserved-regex
```

## Health

**Score 63/100 (C)** — status: active.

Positive: has types package; esm support; no vulnerabilities; recently updated; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2026-08-28 |
| First published | 2015-01-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/filename-reserved-regex) |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | regex, regexp, filename, reserved, illegal |

## Links

- npm: https://www.npmjs.com/package/filename-reserved-regex
- Repository: https://github.com/sindresorhus/filename-reserved-regex
- Homepage: https://github.com/sindresorhus/filename-reserved-regex#readme
- Issues: https://github.com/sindresorhus/filename-reserved-regex/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/filename-reserved-regex

## Recent versions

- 4.0.1 (latest) — 2026-08-28
- 4.0.0 — 2025-09-14
- 3.0.0 — 2021-08-16
- 2.0.0 — 2016-10-10
- 1.0.0 — 2015-01-14

## README

# filename-reserved-regex

> Regular expression for matching reserved filename characters

On Unix-like systems `/` is reserved and [`<>:"/\|?*`](https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions) as well as non-printable characters `\u0000-\u001F` on Windows. Windows also doesn't allow names ending in space or period.

## Install

```sh
npm install filename-reserved-regex
```

## Usage

```js
import filenameReservedRegex, {windowsReservedNameRegex} from 'filename-reserved-regex';

filenameReservedRegex().test('foo/bar');
//=> true

filenameReservedRegex().test('foo-bar');
//=> false

'foo/bar'.replace(filenameReservedRegex(), '!');
//=> 'foo!bar'

windowsReservedNameRegex().test('aux');
//=> true
```

## API

### filenameReservedRegex()

Returns a regex that matches all invalid characters.

### windowsReservedNameRegex()

Returns an exact-match case-insensitive regex that matches reserved Windows device names.

These include `CON`, `PRN`, `AUX`, `NUL`, `CONIN$`, `CONOUT$`, `COM1` through `COM9`, `COM¹`, `COM²`, `COM³`, `LPT1` through `LPT9`, `LPT¹`, `LPT²`, and `LPT³`. `COM0` and `LPT0` are conservatively matched for compatibility with previous versions.

Names followed by an extension are also matched because, for example, `NUL.txt` and `NUL.tar.gz` are both equivalent to `NUL`. ASCII spaces before the extension or at the end of the name are ignored in the same way as on Windows.

---
_Source: https://npm.io/package/filename-reserved-regex · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
