【问题标题】:Find a set of numbes in long string using RegEx使用 RegEx 在长字符串中查找一组数字
【发布时间】:2011-10-28 10:07:18
【问题描述】:

我一直在搜索 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 方面非常基础。

任何帮助都会很棒!

【问题讨论】:

    标签: regex vb.net string search digits


    【解决方案1】:

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

    试试这个

    \d{8}
    

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

    Regexr.com 是一款不错的在线测试工具,可以看this regex here

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

    【讨论】:

    • 是的,这解决了问题。我刚看到。谢谢哥们!
    猜你喜欢
    • 1970-01-01
    • 2012-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-31
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    相关资源
    最近更新 更多