Filename

Regular expression to split a filename.

Usage

var RE_FILENAME = require( '@stdlib/regexp/filename' );

RE_FILENAME

Regular expression to split a filename.

RE_FILENAME.posix

Regular expression to split a POSIX filename.

var parts = RE_FILENAME.posix.exec( '/foo/bar/index.js' ).slice();
/* returns
    [
        '/foo/bar/index.js',  // input value
        '/',                  // root
        'foo/bar/',           // dirname
        'index.js',           // basename
        '.js'                 // extname
    ]
*/

RE_FILENAME.win32

Regular expression to split a Windows filename.

var parts = RE_FILENAME.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 main exported regular expression is platform-dependent. If the current process is running on Windows, RE === RE.win32; otherwise, RE === RE.posix.

Examples

var RE_FILENAME = require( '@stdlib/regexp/filename' );

// 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 = RE_FILENAME.posix.exec( '/foo/bar/home.html' ).slice();
/* returns
    [
        '/foo/bar/home.html',
        '/',
        'foo/bar/',
        'home.html',
        '.html'
    ]
*/

parts = RE_FILENAME.win32.exec( 'C:\\foo\\bar\\home.html' ).slice();
/* returns
    [
        'C:\\foo\\bar\\home.html',
        'C:',
        '\\',
        'foo\\bar\\',
        'home.html',
        '.html'
    ]
*/