正则表达式不匹配的括号与双方括号

Regex Unmatched parenthesis with double Square brackets

我正在寻找逃避方法我尝试了很多但没有用这是 Discover Credit Card 的正则表达式,但我无法将其分组所以可以检查它的长度

这是正则表达式

 ^[(6011|65|64[4-9]|622)(\d{1,4})]{16}$

Link: https://regex101.com/r/yEEpDt/1

如果只想匹配16位,不多不少
并且数字必须以您的组合之一开头,
这是做到这一点的方法。

使用先行断言来验证长度,
然后正常匹配。

https://regex101.com/r/qo2cOL/1

^(?=\d{16}$)(6011|65|64[4-9]|622)(\d{1,14})$

展开

 ^ 
 (?= \d{16} $ )
 (                             # (1 start)
      6011
   |  65
   |  64 [4-9] 
   |  622 
 )                             # (1 end)
 ( \d{1,14} )                  # (2) or even just a \d* will do here
 $