Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 像12345678900这样的字符串的正则表达式模式?_Javascript_Regex - Fatal编程技术网

Javascript 像12345678900这样的字符串的正则表达式模式?

Javascript 像12345678900这样的字符串的正则表达式模式?,javascript,regex,Javascript,Regex,正如您从标题中所看到的,我想编写一个正则表达式模式来查找由各种数字组成的字符串,该字符串每三位用逗号分隔。字符串的长度可以变化 我对正则表达式还是很陌生,有人能帮我吗?先谢谢你 附言。 任何人都可以推荐一些学习正则表达式的好资源,如网站、书籍等。此正则表达式应与以下内容匹配: \d{1,3}(?:,\d{3})* 如果要排除与格式错误模式的子字符串的匹配,可能需要执行以下操作: (?:\A|[^,\d])(\d{1,3}(?:,\d{3})*)(?:\z|[^,\d]) 第一个正则表达式的解

正如您从标题中所看到的,我想编写一个正则表达式模式来查找由各种数字组成的字符串,该字符串每三位用逗号分隔。字符串的长度可以变化

我对正则表达式还是很陌生,有人能帮我吗?先谢谢你

附言。
任何人都可以推荐一些学习正则表达式的好资源,如网站、书籍等。

此正则表达式应与以下内容匹配:

\d{1,3}(?:,\d{3})*
如果要排除与格式错误模式的子字符串的匹配,可能需要执行以下操作:

(?:\A|[^,\d])(\d{1,3}(?:,\d{3})*)(?:\z|[^,\d])
第一个正则表达式的解释

\d{1,3}        1 to 3 consecutive numerals
,\d{3}         A comma followed by 3 consecutive numerals
(?:,\d{3})*    Zero or more repetition of a non-capturing group of a comma followed by 3 consecutive numerals
(?:\A|[^,\d])         A non-capturing group of either the beginning of the string, or anything other than comma or numeral
(\d{1,3}(?:,\d{3})*)  A capturing group of 1 to 3 consecutive numerals followed by zero or more repetition of a non-capturing group of a comma followed by 3 consecutive numerals
(?:\z|[^,\d])         A non-capturing group of either the end of the string, or anything other than comma of numeral
第二个正则表达式的解释

\d{1,3}        1 to 3 consecutive numerals
,\d{3}         A comma followed by 3 consecutive numerals
(?:,\d{3})*    Zero or more repetition of a non-capturing group of a comma followed by 3 consecutive numerals
(?:\A|[^,\d])         A non-capturing group of either the beginning of the string, or anything other than comma or numeral
(\d{1,3}(?:,\d{3})*)  A capturing group of 1 to 3 consecutive numerals followed by zero or more repetition of a non-capturing group of a comma followed by 3 consecutive numerals
(?:\z|[^,\d])         A non-capturing group of either the end of the string, or anything other than comma of numeral
请尝试一些好的示例和工具链接,以帮助您了解RegEx

也可以试试这个正则表达式测试程序


还有一个我以前使用过的工具

一些参考资料:供参考还不错。对于测试,或者可能是MSDN、PHP、Java和Mozila JavaScript文档,都有关于如何执行正则表达式的指南,大多数情况下它们不是特定于语言的,因此您可以阅读其中的任何一个。我个人喜欢PHP和Mozilla文档…还没有阅读MSDN文档。你能试试这个正则表达式吗:
^\d{1,3}(?:,\d{3})*$
@anubhava,仅当整个字符串是数字时才匹配。它匹配逗号之间的4位数字。我尝试了它,但它不匹配…regexpal有什么问题吗?@sawa如果您尝试在此页面上测试12345678900,它将显示“成功匹配”@woodykiddy,我认为应该,它应该匹配
1234
。必须使用
^
$
标记
/^\d{1,3}(?:,\d{3})*$/
否则
1234
匹配。。。