我有下一个字符串:
Numbers: Zero
One
Two
Three
***
(n lines that start with one or more whitespace chars)
***
Name\Fruits\etc: John
Jane
我想(与正则表达式),其开头的字符串“号:”直到与非空白字符开头的下一行(没有这条线......)。
我在我的例子中,后的下一行的“数字”与非空白字符开头是:“名称\水果\等:约翰”,所以我想:
Zero
One
Two
Three
***
(n lines that start with one or more whitespace chars)
***
您可以使用此
^(?:Numbers:)([\w\W]+?)(?=^\S)
^
- 锚开始的字符串。Numbers:
。([\w\W]+?)
- 匹配任何东西。 (懒惰模式)。(?=^\S)
- 后面必须有非空格字符换行。