js regular expression

/^((1(\s)|)[1-9]{3}(\s|-|)[1-9]{3}(\s|-|)[1-9]{4}) $/
The following is the disassembly analysis

/ /**Regular matching starts**/
^ /**Matches an input or the beginning of a line**/  
(
  (
    1(\s) /**Match 1 and null characters: 1 ** /
    | /** or match nothing: **/
  )
    [1-9]{3} /** match digits 1-9 3 times: 345**/
  (
    \s /** match null character: * */
    |- /** or match the minus sign: -**/
    | /** or match nothing: **/
  )
    [1-9]{3} /** match the number 1-9 3 times: 345**/
  (
    \s /** matches null: **/
    |- /** or matches minus sign: -**/
    | /** or matches nothing: **/
  )
    [1-9] {4} /**Match numbers 1-9 4 times: 3456**/
)
$ /**Match an input or end of a line**/
/ /**Regular match ends**/


Note: The priority of | is lower (1(\s)|) can match 1 but not match 1. Recommended writing ((1\s)|)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326371688&siteId=291194637