Reputation: 327
I need a regex that excludes lines with given strings from matching. Here`s what I found out so far:
Regex:
(?<!\/)\shttps
Test-Text:
string.pdf https
string.html https
stringEndingWithSlash/ https
stringEndingWithoutSlash https
This only excludes the 3rd line. But I need the expression to match only the lines with strings not ending with .pdf, .html or a slash. So only the last line of the example should match. How can I use the logical | or here? Or is there another solution? Thank you - all the best, Sacha
Upvotes: 0
Views: 57
Reputation: 350242
I realise an answer has been accepted, but it will be more efficient to not do a look ahead at each individual character, but do two look-behinds where and when they are needed only:
^.*[^\/] https$(?<!\.pdf https)(?<!\.html https)
... using the gm
flags.
Upvotes: 1
Reputation: 521178
The following pattern seems to be working:
^\w+(?!\.pdf|\.html|\/) https$
This matches some initial word, which does not end in either .pdf
, .html
, or a forward slash, which is then followed by a space and https
. It uses a negative lookahead to do this. While there might be solutions that do not use lookarounds, they seem to be easiest way to implement the logic you want.
Upvotes: 1