0

我的原始文本文件就像

>
 item1
>
item{2}
>
item3
>
item4}

我想删除/匹配所有包含 { 或 } 的项目。在上面的示例中,它将删除第 2 项和第 4 项。结果将是:

>
 item1
>
item3

我想做贪婪匹配,所以它匹配最小块。它还必须匹配多行。喜欢:

(?s)>(.+?)[\{|\}](.+?)>

但这对我来说不能正常工作。

4

2 回答 2

1

This regex does exactly what you asked for. It assumes that exact type of input, with nothing else on the line above the one which contains { or }.

>\n.*?[{}]+.*?$

If that line could have text on it, the following one works.

>.*\n.*?[{}]+.*?$

Both these replaces will leave a blank line. To avoid this, add \n either in front or the back of the regex, depending on what fits your document.

于 2013-05-03T16:15:15.693 回答
0

试试这个:

\n>\s(.*)(\{|\})
于 2013-05-03T16:18:50.190 回答