Reputation: 13
I'm trying to match a string of arbitrary length with a regular expression (in python), that does not contain a single forward- or double backward slashes.
"[^/]*" works just fine for the forward slash, but "[^/\\\\\\\\]" does obviously not work in a set.
How can I match everything but two consecutive backslashes?
Upvotes: 1
Views: 194
Reputation: 361625
The easiest way is to use negative lookahead to exclude the two patterns.
re.match(r'(?!.*/|.*\\\\)', string)
Upvotes: 1