Python regex match, but exclude if regex match
Question:
I’m trying to write a regex for re.search that can match a string as long as the word prod
exists anywhere in the text (.*prod.*
). however, it should fail the match if the string should have the word orange
anywhere in it.
web-prod-green
# should match
web-prod-orange
# should fail to match
web-orange-green
# should fail to match
orange-prod-green
# should fail to match
How can i do this? Thanks.
Answers:
I’m trying to write a regex for re.search that can match a string as long as the word prod
exists anywhere in the text (.*prod.*
). however, it should fail the match if the string should have the word orange
anywhere in it.
web-prod-green
# should matchweb-prod-orange
# should fail to matchweb-orange-green
# should fail to matchorange-prod-green
# should fail to match
How can i do this? Thanks.