我有以下正则表达式^.*?((\yo\b.*?(cut me:)[\s\S]*))$
- 带有ms
标记
正如您所看到的,它匹配" yo"的第一个实例。我希望它匹配" yo"的最后一个实例。最接近"切断我"。我需要这个是multiline-dotall。
如何修改正则表达式以便获得以下匹配的输出?
输出(目前以红色匹配):
yo keep this here
Keep this here
yo
blah, blah, blah cut me:
Allof this here should be deleted
Exptected Output(我希望以红色匹配):
yo
blah, blah, blah cut me:
Allof this here should be deleted
答案 0 :(得分:2)
也许不要先让.*?
不情愿。
^.*((\yo\b.*?(cut me:)[\s\S]*))$
似乎解决了你的问题。
此外,由于您使用的是dotall
标记,因此可能会将[\s\S]
更改为.