[英]Javascript Regex doesn't match the recurring pattern
Input:"[3, 4]", "[1, 2, 7, 7]"
Input:"[13, 4]", "[1, 2, 3, 6, 14]"
Input: "[5, 5]", "[1, 2, 3]"
\"\s*\[[0-9]\s*\,\s*[0-9]\]\"\s*\,\s*\"\[[0-9]\s*\,
这就是我试图验证上述输入的内容。 使用我尝试过的方法,我无法验证字符串的最后一部分。 第二个数据数组可以是任意数量的输入。 上述正则表达式适用于第二个数组的第一个逗号。 现在无法为任何数量的输入编写通用表达式。
如果我理解正确
^\\s*"\\s*\\[\\s*[0-9]+\\s*(?:\\,\\s*[0-9]+\\s*)*\\]\\s*"(?:\\s*,\\s*"\\s*\\[\\s*[0-9]+\\s*(?:\\,\\s*[0-9]+\\s*)*\\]\\s*")*\\s*$
https://regex101.com/r/PpZy8I/1
^ # Begin of string
\s* # Leading wsp
" \s* # Quote start of array
\[ # Array opening
\s* [0-9]+ \s*
(?: # Optional nesting elements comma plus digits
\, \s*
[0-9]+ \s*
)*
\] # Array close
\s*
" # Quote end of array
(?: # Optional many more arrays
\s* , \s*
" \s*
\[
\s* [0-9]+ \s*
(?:
\, \s*
[0-9]+ \s*
)*
\]
\s*
"
)*
\s* # Trailing wsp
$ # End of string
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.