你能建议一个正则表达式来捕获这个文本吗?

时间:2011-09-27 06:00:04

标签: c# regex

请建议使用正则表达式从下面的输入文本中捕获:

Match 0:"Modifications made by ... on2011/07/13 06:17:32 from database
keyword: zzzz--> mmmmmm
total_effort: --> 0.00
tmp__effort: --> 0
resolver"

Match 1:"Modifications made by ... on2011/07/13 06:19:32 from database
resolver"

输入文字:

Modifications made by... on 2011/06/21 14:09:14 from database
problem_description: (text value has changed)


Modifications made by ... on2011/07/13 06:17:32 from database
keyword: zzzz--> mmmmmm
total_effort: --> 0.00
tmp__effort: --> 0
resolver: y --> x
total_t_effort: --> 0.00

Modifications made by ... on2011/07/13 06:19:32 from database
resolver: x --> z
total_t_effort: --> 0.00




我已尝试使用此modifications\smade\sby(.|\n)+?resolver,但它给出了错误的输出:

Match 0:"Modifications made by... on 2011/06/21 14:09:14 from database
problem_description: (text value has changed)


Modifications made by ... on2011/07/13 06:17:32 from database
keyword: zzzz--> mmmmmm
total_effort: --> 0.00
tmp__effort: --> 0
resolver"
Match 1:"Modifications made by ... on2011/07/13 06:19:32 from database
resolver"

使用的选项:IgnoreCase + MultiLine

有人可以帮忙吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

如果你想使用正则表达式,它会变得有点复杂。

尝试

^modifications\smade\sby(.(?!modifications))+?resolver

here on Regexr

我删除了\n并改为使用 Singleline option

这个想法是,匹配每个字符直到下一个“解析器”,但只有当这个字符后面没有“修改”时。因此,我使用了负向前瞻.(?!modifications)