RegEx for selecting the first element of a path -
my question pretty simple, write regex this:
/ -> /
/foo -> /foo
/foo/bar -> /foo
/foo/bar/baz -> /foo
i've tried this:
replace(/(\/[^\/]*)\/[^\/]*/, '$1')
but returns path, unmodified.
does know how do?
this should work:
/^\/[^\/]*/ it match start slash , chars until slash found (excepting 2nd slash)
'/test'.match(/^\/[^\/]+/)[0] will return '/test'
'/test/asd'.match(/^\/[^\/]+/)[0] will return '/test'
strings don't start slash not match.
Comments
Post a Comment