Filename Extension

Regular expression to capture a filename extension.

Usage

var RE_EXTNAME = require( '@stdlib/regexp/extname' );

RE_EXTNAME

Regular expression to capture a filename extension.

RE_EXTNAME.posix

Regular expression to capture a POSIX filename extension.

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

RE_EXTNAME.win32

Regular expression to capture a Windows filename extension.

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

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

var ext;

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

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

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