.net - 正则表达式查找未注释掉的标签之间的文本

标签 .net regex expression

我有一个简单的场景似乎难倒了我。我想获取两个未注释掉的标签之间的文本。这是一个例子:

// Example of commented text
// :Start
// <I don't want to get this text>
// :End


:Start
<Here is the text i want>
:End

解决方案:

感谢大家的帮助。非常快地收到了答案,并且完全满足了我的需要。我使用以下正则表达式,因为它最适合我的情况。特别感谢蒂姆·皮茨克:

(?sm)(?<=^:Start\s*)(?:(?!^:End).)*

最佳答案

试试这个:

(?sm)(?<=^:Start\s*)(?:(?!^:End).)*

说明:

(?sm)     # Set options: . matches newline, ^ matches start-of line
(?<=      # Assert that this regex can be matched before the current position:
 ^        #  Start of line
 :Start   #  :Start
 \s*      #  Any whitespace
)         # End of lookahead
(?:       # Try to match...
 (?!      # (unless the following regex could be matched here:)
   ^      #  Start of line
   :End   #  :End
 )        #  End of lookahead
 .        # ... any character
)*        # Repeat any number of times

关于.net - 正则表达式查找未注释掉的标签之间的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12804865/

相关文章:

c# - 如何使用 TPL 并行化文件写入?

html - 怎么办 正则表达式模式在字符串中的任何地方都不匹配?

javascript - 很好地显示数值

java - log4.xml 中用于访问 java 系统属性的表达式语言是什么?

c# - 无法从 'method group' 转换为 'Func<string, string, bool>'

android - 在 .net 上开发自己的 android 应用程序 - 什么免费框架?

sed - 如何使用sed在正则表达式中转义减号?

Java 8 : How Lambda expression impacts

.net - 单击后如何保持打开 rad 菜单?

java - 获取在正则表达式中进行匹配的组的编号/ID