I want to detect whether a word is in a sentence using python regex. Also, want to be able to negate it.
import re
re.match(r'(?=.*foo)', 'bar red foo here')
this code works but I do not understand why I need to put .*
in there.
Also to negate it, I do not know how to do that.
I've tried:
re.match(r'(?!=.*foo)', 'bar red foo here')
but it does not work.
My ultimate goal is to combine them like so:
re.match(r'(?=.*foo)(?!=.*bar)', 'bar red foo here')
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…