Skip to content

Files

Latest commit

b00e510 · Dec 6, 2016

History

History

dirname

README.md

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.

var dir;

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

// On a Windows platform...
dir = RE_DIRNAME.exec( 'C:\\foo\\bar\\index.js' )[ 1 ];
// returns 'C:\\foo\\bar'

RE_DIRNAME.posix

Regular expression to capture a POSIX path dirname.

RE_DIRNAME.win32

Regular expression to capture a Windows path dirname.

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'