【问题标题】:sublime text regex multiple parameters崇高文本正则表达式多个参数
【发布时间】:2014-02-19 16:58:10
【问题描述】:

我想在 Sublime Text 中使用正则表达式来获取 Parameter1。其他参数将不使用。

初始标签:

<description><![CDATA[<b>Parameter1</b></br></br> 
This not to be copied and can be long]]></description>

Regex Sublime Text 中的这个表达式...

<description><!\[CDATA\[<b>(\w+)</b></br></br>(\w*)\]\]</description>

找不到我需要的东西(当我到达时停止寻找)

【问题讨论】:

    标签: regex sublimetext2


    【解决方案1】:

    您的正则表达式与测试字符串不匹配。
    单词字母之间有空格。
    它也不会匹配标点符号等非单词字母。

    下面是两个正则表达式

    1. 这只是为了匹配您的测试字符串。

     # <description>\s*<!\[CDATA\[\s*<b>([\s\w]+)</b>\s*</br>\s*</br>([\s\w]*)\]\]\s*</description>
    
     <description>
     \s* 
     <!\[CDATA\[
     \s* 
     <b>
     (                                 # (1)
          [\s\w]+ 
     )
     </b> \s* </br> \s* </br>
     (                                 # (2)
          [\s\w]* 
     )
     \]\]
     \s* 
     </description>
    

    2. 如果您的引擎支持前瞻断言,则应该这样做。

     # (?s)<description>\s*<!\[CDATA\[\s*<b>((?:(?!\]\]|\s*</b>).)+?)\s*</b>\s*</br>\s*</br>\s*((?:(?!\s*\]\]).)*)\s*\]\]\s*</description>
    
     (?s)
     <description>
     \s* 
     <!\[CDATA\[
     \s* 
     <b>
     (                                 # (1)
          (?:
               (?! \]\] | \s* </b> )
               . 
          )+?
     )
     \s* </b> \s* </br> \s* </br> \s* 
     (                                 # (2)
          (?:
               (?! \s* \]\] )
               . 
          )*
     )
     \s* 
     \]\]
     \s* 
     </description>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-06
      • 2017-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      • 1970-01-01
      相关资源
      最近更新 更多