Reputation: 23315
I'm trying to build a regular expression that can match paired forward slashes (e.g. /something/
), but skip escaped pairs (e.g. \/something\/
) and also skip something like subsequent URL's (e.g. http://something.com and stuff http://somethingelse.org
).
So, in the following example, only the text "jumped over" would be matched, nothing else would be a match:
The quick brown fox /jumped over/ the lazy dogs. He was looking for a \/website\/ to help him find ways around the dogs because he was sick of \/jumping\/ over them. Unfortunately, both http://routesaroundlazydogs.com/ and https://maps.lazydogs.com/stuff/things/findmap.aspx were both down on the day he was looking.
The regex has to work in Javascript (i.e. no look-behinds).
Upvotes: 0
Views: 132
Reputation: 784998
How about using this regex:
\\\/.*?\\\/|\/\/\S*|\/(.*?[^\\])\/
And use matched group #1 for your match.
Upvotes: 1
Reputation: 37763
Tricky, since you probably want foo /bar/ foo /bar/ foo
to not match / foo /
.
I'd suggest finding a url regex, then doing input.replace(urlRegex, "")
, then writing a simple parser to read in the /
pairs instead of a regex.
Upvotes: 0