正则表达式匹配冗余字符串集团

时间:2014-04-10 07:58:53

标签: regex

我正在使用arround来创建一个与字符串的某个块匹配的正则表达式,它包含许多类似块的问题,并且它没有明确分离,因此我无法告诉如何停止正则表达式。

字符串

的示例
  A1, \field Do Zone Sizing Calculation
      \note If Yes, Zone sizing is accomplished from corresponding Sizing:Zone objects
      \note and autosize fields.
      \type choice
      \key Yes
      \key No
      \default No
  A1, \field Do Zone Sizing Calculation
      \note If Yes, Zone sizing is accomplished from corresponding Sizing:Zone objects
      \note and autosize fields.
      \type choice
      \key Yes
      \key No
      \default No

所以我要做的是匹配并仅选择第一个A1。 这是我到目前为止所做的:

^\s{2}((A\d,|N\d,)|(A\d;|N\d;))(.*?\n\s{2})*

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,以防任何人碰巧遇到同样的问题。

^\s{2}((A\d,|N\d,)|(A\d;|N\d;)).*\n(\s{6}.*?\n)*