/ ^ (18 [0-9] {9}) | (15 [0-9] {9}) $/ regular matching problem

/ ^ (18 [0-9] {9}) | (15 [0-9] {9}) $/ Why the rule matches 1844444444444444 . My understanding of this rule is starting with 18 or 15 followed by 9 digits 0-9 .

Note: I know there are other ways to write the rules of mobile phone numbers. I just want to understand why this one matches.


/^(18[0-9]{9})|(15[0-9]{9})$/

this expression is equivalent to:

/(^18[0-9]{9})|(15[0-9]{9}$)/

is because the priority ratio of ^ and $is higher than |, so ^ matches 18 [0-9] {9} first


/^(18[0-9]{9})$|^(15[0-9]{9})$/ 

because the previous 11 bits have been matched successfully
your expression cannot match


at the beginning of 15.
^(18[0-9]{9})|(15[0-9]{9})$

your way of writing is equivalent to

^(18[0-9]{9})

or


  (15[0-9]{9})$

, that is, the priority question, you need to add parentheses as follows:

^((18[0-9]{9})|(15[0-9]{9}))$

in fact, this js library already has API for verifying mobile phone numbers. Please refer to bee.js

.

/ ^ (18 [0-9] {9}) | (15 [0-9] {9}) $/

first of all, you need to understand what the rule you are writing means:
^ (18 [0-9] {9}) or (15 [0-9] {9}) $matches

translates as:
(beginning with 18 and 9 decimal numbers) or (15 and 9 decimal endings) match

then the data you give goes like this:
1844444444444444444444

since it is an or statement, it matches the beginning of 18 and 9 decimal numbers, so it naturally matches

.

can be changed to this / ^ (18 [0-9] {9}) $| ^ (15 [0-9] {9}) $/ match your desired mobile phone

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e99222-1734.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e99222-1734.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?