0

Im trying to preform a regex search in python. I have a string which can be either domain.com/user or domain.com/123

However I want to preform a match if the string is domain.com and /user is NOT found.

import re
re.search('domain.com!(/user)',src,re.IGNORECASE)

Can you please assist, Thanks,

1 Answer 1

1

What you want is called a negative look-ahead assertion.

import re

print bool(re.search("domain.com(?!/user/)", "domain.com"))
print bool(re.search("domain.com(?!/user/)", "domain.com/user/test"))
print bool(re.search("domain.com(?!/user/)", "domain.com/test"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.