简体   繁体   English

正则表达式匹配 Javascript 中大文档中的数字

[英]Regex to match numbers from large document in Javascript

Trying to create a regex that could match numbers from large document.试图创建一个可以匹配大文档中数字的正则表达式。

Find at least 10 continuous digits (which can go to maximum 15 digits) that could be separated by one or multiple找到至少 10 个可以由一个或多个分隔的连续数字(最多可以达到 15 个数字)

-
_
\s
(
)
[
] 

Tried-试过-

/(?:((\d([ \-_\s]+?)){5,8}))/

Eg:例如:

1-2-3-4-5-6-7-8-9-0-12-34
1 2 3 4 5 6 7 8 9 0
123-456-789-0
123---456---789---987
12 34 56 78 90
12_ -34_-56--78__90



You may use您可以使用

/\d(?:[-_\][()\s]*\d){9,14}/g

See the regex demo查看正则表达式演示

Details细节

  • \\d - a digit \\d - 一个数字
  • (?:[-_\\][()\\s]*\\d){9,14} - 9 to 14 repetitions of (?:[-_\\][()\\s]*\\d){9,14} - 9 到 14 次重复
    • [-_\\][()\\s]* - 0 or more repetitions of - , _ , ] , [ , ( , ) or whitespace [-_\\][()\\s]* - 0 次或多次重复- , _ , ] , [ , ( , )或空格
    • \\d - a digit. \\d - 一个数字。

Note you do not need to escape [ inside a character class, it is parsed as a literal [ in a JS regex.请注意,您不需要在字符类中转义[ ,它在 JS 正则表达式中被解析为文字[ However, ] must be escaped there, otherwise, it will close the character class prematurely.但是, ]必须在那里转义,否则会过早关闭字符类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM