What could be regex which match anystring followed by daily but it must not match daily preceded by m?
For example it should match following string
beta.dailyabcdailydailyabcdailyBut it must not match
mdaily orabcmdaily ormdailyabcI have tried following and other regex but failed each time:
r'[^m]daily': But it doesn't match with daily
r'[^m]?daily' : It match with string containing mdaily which is not intended(. *?) matches any character ( . ) any number of times ( * ), as few times as possible to make the regex match ( ? ). You'll get a match on any string, but you'll only capture a blank string because of the question mark.
There's two ways to say "don't match": character ranges, and zero-width negative lookahead/lookbehind. Also, a correction for you: * , ? and + do not actually match anything. They are repetition operators, and always follow a matching operator.
In this example, [0-9] matches any SINGLE character between 0 and 9 (i.e., a digit), where dash ( - ) denotes the range. The + , known as occurrence indicator (or repetition operator), indicates one or more occurrences ( 1+ ) of the previous sub-expression. In this case, [0-9]+ matches one or more digits.
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.
Just add a negative lookbehind, (?<!m)d, before daily:
(?<!m)daily
The zero width negative lookbehind, (?<!m), makes sure daily is not preceded by m.
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With