c# - 使用 C# 的正则表达式

标签 c# regex

我试图找到一个匹配以下字符串的正则表达式:

##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/

相关文章:

c# - 如何通过将所有元素加或在一起来简化列表?

c# - 如果连接在 .NET 远程服务器上的远程调用中途终止,会发生什么情况?

c# - 对象列表的回发为空

python - 如何将以建筑格式显示的测量值转换为 float ?

c++ - 在QML中将regExp创建到textField

c# - 如何在 asp.net 的 ViewState 中存储数组?

c# - 线程被中止 - 同时循环了很多行

ruby - 如何在 Ruby 中保留 float 的同时拆分包含算术表达式的字符串

c# - 选择除一个扩展名之外的所有文件

java - 电子邮件模式元注释中使用的正则表达式不起作用,但在其他地方起作用