如何构建一个正则表达式,匹配一个包含任何字符但必须包含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
- [^,zero or more times again
- $ End of string