# Filename
> [Regular expression][mdn-regexp] to split a filename.
## Usage
```javascript
var reFilename = require( '@stdlib/regexp/filename' );
```
#### reFilename( \[platform] )
Returns a [regular expression][mdn-regexp] to split a filename.
```javascript
var RE = reFilename();
// returns
RE = reFilename( 'posix' );
// returns
var parts = RE.exec( '/foo/bar/index.js' ).slice();
/* returns
[
'/foo/bar/index.js', // input value
'/', // root
'foo/bar/', // dirname
'index.js', // basename
'.js' // extname
]
*/
RE = reFilename( 'win32' );
// returns
parts = RE.exec( 'C:\\foo\\bar\\index.js' ).slice();
/* returns
[
'C:\\foo\\bar\\index.js', // input value
'C:', // device
'\\', // slash
'foo\\bar\\', // dirname
'index.js', // basename
'.js' // extname
]
*/
```
#### reFilename.REGEXP
[Regular expression][mdn-regexp] to split a filename.
```javascript
var bool = ( reFilename.REGEXP.toString() === reFilename().toString() );
// returns true
```
#### reFilename.REGEXP_POSIX
[Regular expression][@stdlib/regexp/filename-posix] to split a [POSIX][posix] filename.
```javascript
var parts = reFilename.REGEXP_POSIX.exec( '/foo/bar/index.js' ).slice();
/* returns
[
'/foo/bar/index.js', // input value
'/', // root
'foo/bar/', // dirname
'index.js', // basename
'.js' // extname
]
*/
```
#### reFilename.REGEXP_WIN32
[Regular expression][@stdlib/regexp/filename-windows] to split a Windows filename.
```javascript
var parts = reFilename.REGEXP_WIN32.exec( 'C:\\foo\\bar\\index.js' ).slice();
/* returns
[
'C:\\foo\\bar\\index.js', // input value
'C:', // device
'\\', // slash
'foo\\bar\\', // dirname
'index.js', // basename
'.js' // extname
]
*/
```
## Notes
- The as `REGEXP` exported [regular expression][mdn-regexp] is [platform][@stdlib/assert/is-windows]-dependent. If the current process is running on Windows, `REGEXP === REGEXP_WIN32`; otherwise, `REGEXP === REGEXP_POSIX`.
## Examples
```javascript
var reFilename = require( '@stdlib/regexp/filename' );
var RE_FILENAME = reFilename();
// Assuming a POSIX platform...
var parts = RE_FILENAME.exec( '/foo/bar/index.js' ).slice();
/* returns
[
'/foo/bar/index.js',
'/',
'foo/bar/',
'index.js',
'.js'
]
*/
parts = reFilename.REGEXP_POSIX.exec( '/foo/bar/home.html' ).slice();
/* returns
[
'/foo/bar/home.html',
'/',
'foo/bar/',
'home.html',
'.html'
]
*/
parts = reFilename.REGEXP_WIN32.exec( 'C:\\foo\\bar\\home.html' ).slice();
/* returns
[
'C:\\foo\\bar\\home.html',
'C:',
'\\',
'foo\\bar\\',
'home.html',
'.html'
]
*/
```
[mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
[posix]: https://en.wikipedia.org/wiki/POSIX
[@stdlib/assert/is-windows]: https://www.npmjs.com/package/@stdlib/assert-is-windows
[@stdlib/regexp/filename-posix]: https://www.npmjs.com/package/@stdlib/regexp/tree/main/filename-posix
[@stdlib/regexp/filename-windows]: https://www.npmjs.com/package/@stdlib/regexp/tree/main/filename-windows