0

我一直在搜索 Stackoverflow,但找不到可以帮助我的确切线程。

我的问题是,我希望能够找到并取出字符串中出现的任何 8 位数字。

Dim SetOfMatches As MatchCollection
Dim MyRegex As New Regex("A^\d{8}$A")
Dim TestString As String = "testing 12345678 testing"
myMatches = myRegex.Matches(TestString)

For each Row as Match in myMatches

console.writeline(row.value)

Next

这不会产生任何点击。但我想在字符串中间找到 8 位数字。

我在 RegEx 中非常基础。

任何帮助都会很棒!

4

1 回答 1

2

有什么A用?我认为你不需要它们。

试试这个

\d{8}

^是字符串开头和结尾的锚点$。所以使用那些它不会在字符串中找到和数字。

Regexr.com 是一个很好的在线测试工具,你可以在这里看到这个正则表达式

正则表达式的另一个好来源是regular-expressions.info

于 2011-10-28T10:15:18.457 回答