从字符串中提取特定长度的数字

Extract specific length numbers from a string

我需要能够使用经典 asp 从字符串中提取特定长度的数字,例如 12 位数字,这样我就可以将它们插入到 table 的单独行中。

数字在字符串中的位置会比较随机,可能有1个,也可能有50个12位数字

字符串示例是:

1. 100001693263 Budrium Pty Ltd ,13059 [=10=].00 -,13.59 2. 100000970265 Heriium Pty Ltd ,63.64 [=10=].00 -,33.64 3. 100001730295 SURFE LOCKSMITHS 87.60 ,32.00 -,5.60

当然有3个。

有人可以帮忙吗?我用谷歌搜索了很多,但没有找到足够具体的内容。如果我能得到代码,它只是转储 3 个数字,例如在它自己的字符串中,用逗号或类似的东西分隔,我也不会大惊小怪。

您可以使用 return 任何一组 12 位数字字符 (0-9) 的正则表达式:(\d{12})

试试这个代码:

text = "100001693263 Budrium Pty Ltd ,13059 [=10=].00 -,13.59 2. 100000970265 Heriium Pty Ltd ,63.64 [=10=].00 -,33.64 3. 100001730295 SURFE LOCKSMITHS 87.60 ,32.00 -,5.60"

Set regex = New RegExp
regex.Global = true
regex.Pattern = "(\d{12})"

Set matches = regex.Execute(text)
 
For each match in matches
   Response.Write(match.Value & "<br />")
Next

备注:

  • Global Property:

    Sets or returns a Boolean value that indicates if a pattern should match all occurrences in an entire search string or just the first one.