time-to-botec/squiggle/node_modules/@stdlib/regexp/filename
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00
..
docs feat: add the node modules 2022-12-03 12:44:49 +00:00
lib feat: add the node modules 2022-12-03 12:44:49 +00:00
package.json feat: add the node modules 2022-12-03 12:44:49 +00:00
README.md feat: add the node modules 2022-12-03 12:44:49 +00:00

Filename

Regular expression to split a 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'
    ]
*/