[英]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.