What could be regex which match anystring
followed by daily
but it must not match daily
preceded by m
?
什么可以是正则表达式匹配anystring后跟每天,但它必须不匹配每天前面的m?
For example it should match following string
例如,它应匹配以下字符串
beta.daily
- beta.daily
abcdaily
- abcdaily
dailyabc
- dailyabc
daily
- 日常
But it must not match
但它一定不匹配
-
mdaily
or - mdaily或
-
abcmdaily
or - abcmdaily或
mdailyabc
- mdailyabc
I have tried following and other regex but failed each time:
我试过跟随和其他正则表达式,但每次失败:
-
r'[^m]daily'
: But it doesn't match withdaily
- r'[^ m]每日':但它与每日不匹配
-
r'[^m]?daily'
: It match with string containingmdaily
which is not intended - r'[^ m]?daily':它与包含mdaily的字符串匹配,这不是预期的
1 个解决方案
#1
7
Just add a negative lookbehind, (?<!m)d
, before daily
:
在每天之前添加一个负面的lookbehind,(?<!m)d:
(?<!m)daily
The zero width negative lookbehind, (?<!m)
, makes sure daily
is not preceded by m
.
零宽度负向后观(?<!m)确保每天不以m为前提。
演示
#1
7
Just add a negative lookbehind, (?<!m)d
, before daily
:
在每天之前添加一个负面的lookbehind,(?<!m)d:
(?<!m)daily
The zero width negative lookbehind, (?<!m)
, makes sure daily
is not preceded by m
.
零宽度负向后观(?<!m)确保每天不以m为前提。
演示