我试图将正则表达式与文本匹配,但很难找到完全匹配。 这是测试文本
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.
所以我想做的是在“建立”课程开始之前只选择文字。 这是我正在做的正则表达式,但是我没有在“建立”之前检测到空行,所以我可以在它之前停止,所以它选择所有文本
^[A-Z].*?,(\s*\\.*)*\s*[a-zA-Z0-9,\s\\:.\(\)\*;]*\n
答案 0 :(得分:1)
如果您要做的就是选择所有内容直到第一个空行,请记住它只是连续两个\n
,对吗?你可以使用像
^(?s).*?\n\n
(?s)
是内联标志,表示.
也会匹配换行符。 Demo为了好玩。
如果您想匹配任何这些块(而不仅仅是第一块),您可以使用:
(?s).*?(?:\n\n|$)
删除锚点,(?:...)
是非捕获组,\n\n|$
将捕获空行或文档末尾。
修改强>
如果您担心空行上可能会有空格,可以使用\n\s*\n
,来自@SebastianH的赞美