【发布时间】:2013-02-25 07:10:10
【问题描述】:
我有一个非常简单的问题要问别人 - 但我自己无法回答。我有一个正则表达式模式,适用于两个不同的在线测试人员,其中一个是基于 .net 的。
但在这里它找不到匹配项。任何人都可以帮忙吗?目的是过滤一个可爱的 F# 秘籍页面,使其可打印:)。
我正在指导我最小的弟弟,他正在学习编程的第 4 周 - 这是他的职责,我承认这让我很困惑!任何帮助我都会非常感激!
Public Function FindCode(input As String)
Dim pattern As String = "(?m)(<pre>)(.+)(<\/pre>)\B"
Dim output As New Dictionary(Of Integer, String)
Dim count As Integer
For Each match As Match In Regex.Matches(input, pattern)
output.Add(count, match.Value)
count += 1
Next
Return output.count
End Function
我没有得到执行,我没有得到匹配。
一个例子是
Some random markup <pre> and this stuff in the middle is what I'm after </pre> and there </pre> lots of these in one file </pre> which when I use Regexhero <pre> finds all the tags </pre>
这样我们可能会使用组来列出 pre /pre 标记之间的所有项目。
感谢您这么快的回复!
【问题讨论】:
-
请发布您要匹配的文本、预期结果和实际结果。
-
会不会抛出异常
-
@JonSkeet 好点乔恩,已添加。哦,只是为了爬行...我最近收到了您最新的 C# 深度电子书。好一个!您之前的一篇对闭包的精彩描述从那时起影响了我的编程。
-
@Richard:我添加了一个新答案,我解释了为什么它不匹配并给了你一个解决方案。
-
@Matt 在紧急呼叫客户后刚回到办公室。如果可以的话,我会在回家时检查一下。谢谢 - 我的 iPad 做不到 :)