如何构建一个正则表达式来匹配包含任意字符但必须包含 21 个逗号的任意长度的字符串?
最佳答案
/^([^,]*,){21}[^,]*$/
那是:
^ Start of string
( Start of group
[^,]* Any character except comma, zero or more times
, A comma
){21} End and repeat the group 21 times
[^,]* Any character except comma, zero or more times again
$ End of string
关于regex - 计算字符串中逗号个数的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/863125/