以下是找到某些特征的所有出现,而排除了文本的某些部分

  • 本文关键字:排除 文本 些部 特征 regex
  • 更新时间 :
  • 英文 :


我正在尝试编写一条正则以找到所有出现的'字符,但排除了以[or<并以]或>。

结尾

这是一个模范文字:

This is some text with ' character to find and [text to 'exclude' with letters and numbers 0-9 '' ] and another part of text with 'more characters' to find <and 'more to' exclude> and again some text with 'character' to find

我尝试了带负lookahead的正则态度:

(?!(([|<)[sS]*?(]|>)))'

但是它不起作用。

几个小时后,我用完了想法:(。任何帮助将不胜感激。

您可以使用

[.*?]|<.*?>|(')

并使用捕获的组(请参见Regex101.com 上的演示)或如果您的引擎(PHP,Perl,PCRE一般,...)使用(*SKIP)(*FAIL)版本支持:

(?:[.*?]|<.*?>)(*SKIP)(*FAIL)|'

请参阅后者的演示

最新更新