使用OR的正则表达式模式

程序员Anel

像这样使用模式

Dim regex As New Regex("#(\d{4}$)")

通过这种模式,我可以从字符串中读取值

My #1234 number
My #125542 Number

但是关于

This is my # 1234 number
This is #12345R number

我的正则表达式模式应检索值。

1234
125542
1234
12345
维克多·史翠比维

您可以使用

Dim regex As New Regex("#\s*(\d{4,})")

并且当您获得比赛机会时match.Groups(1).Value

图案细节

  • #-一个#字符
  • \s* -0+空格
  • (\d{4,}) -第1组:四个或更多数字。

请参阅.NET regex演示,结果:

在此处输入图片说明

参见VB.NET演示

Dim r As New Regex("#\s*(\d{4,})")
Dim s As String
s = "My #1234 number, My #125542 Number, This is my # 1234 number, This is #12345R number"
For Each m As Match In r.Matches(s)
    Console.WriteLine(m.Groups(1).Value)
Next

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章