is there a more efficient way to filter regex match string? -


var s = '/home/src/_layouts/default.pug';// wanna '_layouts/default' var regex = /(src\/.*)/; var m = s.match(regex); var t = m[0].match(/([^(src\/)].*)(?=\..*$)/)[0]; console.log(t);// outputs "_layouts/default" 

it works no elegant enough, wanna more efficient, can me? thanks.

the regex you're after /src\/([^.]*)\..+/.

it'll match src, capture before dot. [^.] negated character class ("match except these characters"), meaning it'll filename , not extension.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -