Regex 正则表达式:单词之间的一个接一个单词

Regex 正则表达式:单词之间的一个接一个单词,regex,Regex,考虑到这个示例文本: !important!this is a poor example of a sentence!important! 我试着把每一个单词都匹配在一个字母后面和中间!重要 到目前为止,我已经得到了?如果你想变得贫穷和判刑,你应该在积极的前瞻中添加。*,这样它将匹配尽可能长的时间!重要的在任何地方都遥遥领先,而不仅仅是紧随其后: (?<=!important!.*\ba\s)(\w+)(?=.*!important!) 只是一个猜测,看起来您正在使用一个可变长度的lo

考虑到这个示例文本:

!important!this is a poor example of a sentence!important!
我试着把每一个单词都匹配在一个字母后面和中间!重要

到目前为止,我已经得到了?如果你想变得贫穷和判刑,你应该在积极的前瞻中添加。*,这样它将匹配尽可能长的时间!重要的在任何地方都遥遥领先,而不仅仅是紧随其后:

(?<=!important!.*\ba\s)(\w+)(?=.*!important!)

只是一个猜测,看起来您正在使用一个可变长度的lookbehind断言。 一般来说,我不会用这个。如果需要,请将其从代码中删除

 #  (?s)(?<=!important!(?:(?!\ba\s).)*\ba\s)((?:(?!!important!).)*)(?=!important!)

 (?s)                          # Dot all
 (?<=                          # Variable length look behind assertion (should not be used really)
      !important! 
      (?:
           (?! \b a \s )
           . 
      )*
      \b a \s 
 )

 (                             # (1 start)
      (?:
           (?! !important! )
           . 
      )*
 )                             # (1 end)
 (?= !important! )             # Look behind assertion (should not be used really)

你能展示一下你是如何尝试向前看的吗?但这不是唯一一个介于a和重要之间的词吗?或者你的实际目标是变得贫穷,例如,a和句子?我想因此变得贫穷和句子
 #  (?s)(?<=!important!(?:(?!\ba\s).)*\ba\s)((?:(?!!important!).)*)(?=!important!)

 (?s)                          # Dot all
 (?<=                          # Variable length look behind assertion (should not be used really)
      !important! 
      (?:
           (?! \b a \s )
           . 
      )*
      \b a \s 
 )

 (                             # (1 start)
      (?:
           (?! !important! )
           . 
      )*
 )                             # (1 end)
 (?= !important! )             # Look behind assertion (should not be used really)