简体   繁体   English

Sublime Text 2:正则表达式删除包含某些字符的块

[英]Sublime Text 2: Regex to remove block containing certain characters

My raw text file is like 我的原始文本文件就像

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

I would like to remove/match all items containing { or }. 我想删除/匹配所有包含{或}的项目。 In the example above, it would be removing item 2 and 4. The result would be: 在上面的示例中,它将删除项目2和4。结果将是:

>
 item1
>
item3

I want to do greedy match so it matches the minimum block. 我想做贪心匹配,所以它匹配最小块。 It also has to match over multiple lines. 它还必须匹配多行。 like: 喜欢:

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

But it's not working properly for me. 但这对我来说无法正常工作。

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. 为避免这种情况,请根据文档的大小在正则表达式的前面或后面添加\\n

试试这个:

\n>\s(.*)(\{|\})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM