Reputation: 2677
Been struggling for the last hour to try and get this regexp to work but cannot seem to crack it.
It must be a regexp and I cannot use split etc as it is part of a bigger regexp that searches for numerous other strings using .test().
(public\/css.*[!\/]?)
public/css/somefile.css
public/css/somepath/somefile.css
public/css/somepath/anotherpath/somefile.css
Here I am trying to look for path starting with public/css followed by any character except for another forward slash.
so "public/css/somefile.css" should match but the other 2 should not.
A better solution may be to somehow specify the number of levels to match after the prefix using something like
(public\/css\/{1,2}.*)
but I can't seem to figure that out either, some help with this would be appreciated.
No idea why this question has been marked down twice, I have clearly stated the requirement with sample code and test cases and also attempted to solve the issue, why is it being marked down ?
Upvotes: 1
Views: 971
Reputation: 87233
You can use this regex
:
/^(public\/css\/[^\/]*?)$/gm
^
: Starts with[^/]
: Not /
*?
: Any Characters$
: Ends withg
: Global Flagm
: Multi-line FlagUpvotes: 2
Reputation: 2219
Something like this?
/public\/css\/[^\/]+$/
This will match public/css/[Any characters except for /]$
$ is matching the end of the string in regex.
Upvotes: 1