Regex 正则表达式检测换行符

Regex 正则表达式检测换行符,regex,Regex,我试图用文本匹配正则表达式,但很难找到精确匹配。 这是测试文本 SimulationControl, \unique-object \memo Note that the following 3 fields are related to the Sizing:Zone, Sizing:System, \memo and Sizing:Plant objects. Having these fields set to Yes but no correspon

我试图用文本匹配正则表达式,但很难找到精确匹配。 这是测试文本

SimulationControl,
      \unique-object
      \memo Note that the following 3 fields are related to the Sizing:Zone, Sizing:System,
      \memo and Sizing:Plant objects.  Having these fields set to Yes but no corresponding
      \memo Sizing object will not cause the sizing to be done. However, having any of these
      \memo fields set to No, the corresponding Sizing object is ignored.
      \memo Note also, if you want to do system sizing, you must also do zone sizing in the same
      \memo run or an error will result.
  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
  A2, \field Do System Sizing Calculation
      \note If Yes, System sizing is accomplished from corresponding Sizing:System objects
      \note and autosize fields.
      \note If Yes, Zone sizing (previous field) must also be Yes.
      \type choice
      \key Yes
      \key No
      \default No

Building,
       \memo Describes parameters that are used during the simulation
       \memo of the building. There are necessary correlations between the entries for
       \memo this object and some entries in the Site:WeatherStation and
       \memo Site:HeightVariation objects, specifically the Terrain field.
所以我要做的是在“构建”类开始之前只选择文本。 这是我正在做的正则表达式,但是我没有在“Building”之前检测到空行,所以我可以在它之前停止,所以它选择了所有文本

^[A-Z].*?,(\s*\\.*)*\s*[a-zA-Z0-9,\s\\:.\(\)\*;]*\n

如果您要做的只是选择第一个空行之前的所有内容,请记住它只是两个连续的
\n
,对吗?你可以用像

^(?s).*?\n\n
(?s)
是一个内联标志,意味着
也将匹配换行符。为了好玩


如果要匹配这些块中的任何一个(而不仅仅是第一个),可以使用:

(?s).*?(?:\n\n|$)
移除锚定,
(?:…)
是非捕获组,
\n\n |$
将捕获空行或文档结尾

编辑


你可以使用<代码> \n*s*\n>代码>如果你担心在空行上可能有尾随的空白,恭喜来自@ SeBasaTyh

这就是我所要寻找的,但是我还有一个问题,文档是由几个块组成的,比如那个,那么我能做些什么来选择文档中间的一个块呢?感谢you@Helmi:根据什么标准?下次请尝试在原始问题中提供这些附加问题,这对每个人都更清楚。我编辑了答案。在许多情况下,你不能确定“空行”完全没有空格(空格、制表符)。那么最好使用像
\n\s*\n
这样的模式,而不是
\n\n
<代码>\s匹配任何空白字符。