首页 > 解决方案 > 需要正则表达式中的建议

问题描述

正则表达式:

.?Description(?:(?!;).)*|.?Resolution(?:(?!;).)*|.?Root Fix(?:(?!;).)* 

输入字符串:

" description: this is first line .
this is second line .
this is thrird ;
and this is some random redundant line "

预期输出:

“description: this is first line .
this is second line .
this is thrird ;”

电流输出:

“description: this is first line .”

任何人都可以更改此表达式以考虑 . 左侧的任何内容(空白行/空格);

标签: regex

解决方案


为什么不匹配所有内容,直到;

[\s\S]*;

演示

编辑:

正如评论中指出的,\S也将包括;,所以更好的方法是:

[^;]*;

演示


推荐阅读