使用正则表达式在长字符串中查找一组数字
我一直在 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 位数字。
我对正则表达式非常基础。
任何帮助都会很棒!
Ive been searching the Stackoverflow but couldnt find the exact thread that could help me.
My problem is this, i want to be able to find and take out any occurances of 8 digits wihtin a string.
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
this doesnt not generate any hits. but i want to find the 8 digit occurance in the middle of the string.
I am very basic in RegEx.
any help would be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
A
有什么用?我认为你不需要它们。试试这个
^
是字符串开头的锚点,$
是字符串结尾的锚点。因此,使用它们将无法在字符串中找到数字。Regexr.com 是一个很好的在线测试工具,你可以在这里看到这个正则表达式。
正则表达式的另一个很好的来源是 regular-expressions.info
What are the
A
good for? I think you don't need them.Try this
The
^
is an anchor for the start of the string and the$
for the end. So using those it will not find and digits within the string.Regexr.com is a good online testing tool, you can see this regex here.
Another good source for regular expressions is regular-expressions.info