繁体   English   中英

在记事本++正则表达式中查找不匹配模式的字符串

[英]Find strings not matching pattern in Notepad++ regex

我想使用Notepad ++正则表达式查找与模式不匹配的所有字符串。

输入文字范例:

{〜Newline〜} {〜Indent,4〜} {〜Colour,Blue〜} 成为或不存在, {〜Newline〜} {〜Indent,6〜} {〜Colour,Green〜} 表示 {〜StartItalic〜 } {〜EndItalic〜} 这个问题。 {〜EndDocument〜}

{~~}之间的部分是减价代码。 其他所有内容都是纯文本。 我想找到所有没有Markdown结构的字符串,并在它们前面插入代码{~Plain~} 结果将如下所示:

{〜Newline〜} {〜Indent,4〜} {〜Colour,Blue〜} {〜Plain〜} 成为或不存在, {〜Newline〜} {〜Indent 6〜} {〜Colour Green〜} {〜平原〜} {〜StartItalic〜} {〜平原〜} {〜EndItalic〜} {〜平原〜} 的问题。 {〜EndDocument〜}

markdown语法是开放式的,因此我不能仅使用可能的代码列表进行处理。

可以在每个{~Plain~}之后插入{~Plain~} ~} ,然后删除每个{~Plain~} ,其后跟{~ ,但这似乎很笨拙。

我希望这适用于当前版本的Notepad ++(暂时没有)。

搭配:

~}((?:[^{]|(?:{[^~]))+){~

然后替换为

~}{~Plain~}$1{~

可能有用。 第一组应该捕获在结束~}和下一个{~之间的所有内容。 只要它们不是开始标签{~一部分,它也将与文本中的{}匹配。

编辑附加说明,因此您可以对其进行更好的修改:

~}             end of previous tag
(              start of the "interesting" group that contains text
  (?:          non-capturing group for +
    [^{]       everything except opening braces
    |          OR
    (?:  
      {        opening brace followed by ...
      [^~]       ... some character which is not `~`
    )
  )+           end of non-capturing group for +, repeated 1 or more times
)              end of the "interesting" group
{~             start of the next tag

这是一个交互式示例: regex101示例

您需要使用负前瞻。 此正则表达式将匹配所有~}出现的内容,因此您可以将它们替换为~}{~Plain~}

~}(?!{~|$)

如果您不想匹配{~Indent,6~} {~Colour,Green~}中的空格,请使用以下命令:

~}(?!{~|$| )

暂无
暂无

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

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