bitgeeky
bitgeeky

Reputation: 319

Regex for escaping path separator in url

I have a url pattern: "somepath/email/". I don't want to write a regex for matching email instead I want anything which isn't a path separator to match email.

Please suggest a regex for this. I am using Python and the url is for a Django application, So any library function will also be helpful but I will prefer a regex.

Upvotes: 3

Views: 1407

Answers (1)

zx81
zx81

Reputation: 41848

The regex [^/\\]+ is a negative character class with a + quantifier and matches any number of characters that are not a / or \\

Code sample:

match = re.search("[^/\\]+", subject)
if match:
    result = match.group()
else:
    result = ""

Upvotes: 2

Related Questions