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
Post a Comment