简体   繁体   English

正则表达式:双引号之间的数字和逗号交替

[英]Regex: number and comma alternation between double quotes

I need to create a regex that matches a "1,2,3,10,12312" pattern.我需要创建一个匹配"1,2,3,10,12312"模式的正则表达式。

As I understand it would start with /([""']) to match the double quotes but I'm lost when I try to get to the \\d digit and comma alternation.据我所知,它会以/([""'])开头来匹配双引号,但是当我尝试使用 \\d 数字和逗号交替时,我迷路了。

what would be a valid regex to do that?什么是有效的正则表达式来做到这一点?

You have some choices, one being:您有一些选择,其中之一是:

"\d+(?:,\d+)*"

To even allow empty double quotes ( "" ), change the expression to要甚至允许空双引号 ( "" ),请将表达式更改为

"\d*(?:,\d+)*"

See a demo on regex101.com .在 regex101.com 上查看演示

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

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