c# - How tho get the whole section with regex (until a line doesn't start with whitespace )
问题描述
I have the next string:
Numbers: Zero
One
Two
Three
***
(n lines that start with one or more whitespace chars)
***
Name\Fruits\etc: John
Jane
I want to get (with regex) the string that starts with "Numbers:" until the next line that starts with non-whitespace character (without this line...).
I my example, the next line after "Numbers:" that starts with non-whitespace character is: "Name\Fruits\etc: John", so I want to get:
Zero
One
Two
Three
***
(n lines that start with one or more whitespace chars)
***
解决方案
你可以用这个
^(?:Numbers:)([\w\W]+?)(?=^\S)
^
- 锚定到字符串的开头。- (?:Numbers:) - 非捕获组,匹配
Numbers:
. ([\w\W]+?)
- 匹配任何东西。(懒惰模式)。(?=^\S)
- 必须后跟非空格字符的换行符。
推荐阅读
- squarespace - 自定义 css 光标不适用于 vimeo 块
- azure - IIS 重写规则以排除虚拟目录
- r - 如何计算偏差标准信息到 mcmc 模型
- python - 是否可以获得(可能已装饰的)Python 函数体的源代码,包括内联注释?
- python - 我们如何在 Python 中删除 Google 电子表格中的行?
- mysql - mysql 在不包含指定字符串的字符串之前的字段中添加文本
- python - XPath 使用包含文本()获取下一个元素?
- python - 使用主页按钮和页面按钮导航 Django 应用程序
- java - 如何在给定存储桶名称和密钥的情况下构造 Amazon S3 URI?
- powershell - PS 脚本在所有 OU 中搜索“Servers”并将它们移动到“Servers”OU