【发布时间】:2018-06-07 21:20:21
【问题描述】:
我正在尝试使用正则表达式来捕获部分标题,但是为什么我能够用它来捕获“4.1 General”,但是如果我在正则表达式 \n([\d\.]+ ?\w+)\n 的末尾添加一个换行符,它就不再捕获那条线?后面不是换行还是我遗漏了什么?
Here's my example for reference
\n([\d\.]+ ?\w+)
输入
3.6.10
POLLUTION DEGREE 4
continuous conductivity occurs due to conductive dust, rain or other wet conditions
3.6.11
CLEARANCE
shortest distance in air between two conductive parts
3.6.12
CREEPAGE DISTANCE
shortest distance along the surface of a solid insulating material between two conductive
parts
4 Tests
4.1 General
Tests in this standard are TYPE TESTS to be carried out on samples of equipment or parts.
\n([\d\.]+ ?\w+)\n? 似乎也不起作用。
【问题讨论】:
-
它与
\n不匹配,因为上一个匹配项有它。使用$和m修饰符,或(?=\n)。见regex101.com/r/EGyxI4/2。在 .NET 中,使用 CRLF 结尾,您将需要(?m)\n([\d.]+ ?\w+)\r?$。甚至(?m)^(\d[\d.]* ?\w+)\r?$. -
谢谢。我认为单独的比赛可以共享项目。这更有意义。