Dirname

Regular expression to capture a path dirname.

Usage

var RE_DIRNAME = require( '@stdlib/regexp/dirname' );

RE_DIRNAME

Regular expression to capture a path dirname.

RE_DIRNAME.posix

Regular expression to capture a POSIX path dirname.

var dir = RE_DIRNAME.posix.exec( '/foo/bar/index.js' )[ 1 ];
// returns '/foo/bar'

RE_DIRNAME.win32

Regular expression to capture a Windows path dirname.

var dir = RE_DIRNAME.win32.exec( 'C:\\foo\\bar\\index.js' )[ 1 ];
// returns 'C:\\foo\\bar'

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_DIRNAME = require( '@stdlib/regexp/dirname' );

var dir;

// Assuming a POSIX platform...
dir = RE_DIRNAME.exec( '/foo/bar/index.js' )[ 1 ];
// returns '/foo/bar'

dir = RE_DIRNAME.posix.exec( '/foo/bar/home.html' )[ 1 ];
// returns '/foo/bar'

dir = RE_DIRNAME.win32.exec( 'C:\\foo\\bar\\home.html' )[ 1 ];
// returns 'C:\\foo\\bar'