@stdlib/regexp-filename
v0.2.2
Published
Return a regular expression to split a filename.
Downloads
11
Readme
reFilename
Regular expression to split a filename.
Installation
npm install @stdlib/regexp-filename
Usage
var reFilename = require( '@stdlib/regexp-filename' );
reFilename( [platform] )
Returns a regular expression to split a filename.
var RE = reFilename();
// returns <RegExp>
RE = reFilename( 'posix' );
// returns <RegExp>
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 <RegExp>
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 to split a filename.
var bool = ( reFilename.REGEXP.toString() === reFilename().toString() );
// returns true
reFilename.REGEXP_POSIX
Regular expression to split a POSIX filename.
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 to split a Windows filename.
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 is platform-dependent. If the current process is running on Windows,REGEXP === REGEXP_WIN32
; otherwise,REGEXP === REGEXP_POSIX
.
Examples
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'
]
*/
See Also
@stdlib/regexp-filename-posix
: return a regular expression to split a POSIX filename.@stdlib/regexp-filename-windows
: return a regular expression to split a Windows filename.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.