Reputation: 37268
I am trying to split the string "/home/noit/"
to become ["/", "home/", "noit/"]
- every component must end in a slash.
I tried this '/home/noit/'.split(/\b(?=\/)/)
which gives me ["/home", "/noit", "/"]
which is reverse of what I was trying to get.
Is it possible to split with regex to get ["/", "home/", "noit/"]
?
Upvotes: 1
Views: 72
Reputation: 13973
This one works, using a word boundary \b
followed by a positive lookahead excluding the slash:
const x = '/home/noit/';
console.log(x.split(/\b(?=[^\/])/));
Upvotes: 1