我试图找到一个匹配以下字符串的正则表达式:
##Content##
##AnotherArea##
到目前为止我已经尝试过
@"\\#\\#(.*?)\\#\\#"
@"\\#\\#(*?)\\#\\#"
但运行时似乎都没有发现任何东西:
foreach (var match in Regex.Matches(txtPageContent.Text, expressionMatch))
其中表达式匹配是包含表达式的字符串。
谁能帮我解决这个问题?
最佳答案
无需转义#
。
##.*?##
简单的解释
Options: ^ and $ match at line breaks
Match the characters “##” literally «##»
Match any single character that is not a line break character «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the characters “##” literally «##»
关于c# - 使用 C# 的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12833168/