I have a string of mobile phone numbers: & #039; 1314107888413161143334132633622241851192555418612623450131411022881316114666213263370884185136088841861262555513141108580131611 46667132633899941326445999218600004038... I have a set of mobile phone numbers: '2017 13141078884 13161143334 13263362224 18511925554 18612623450 13141102288 13161146662 13263370884 18513608884 18612625555 13141108580 13161146667 13263389994 13264459992 18600004038 '. The last four matching mobile phones have at least eight What should I do with regular numbers?
Do not make effort. For example, (8 \ d {3} | \ d8 \ d | \ d \ d8 \ d | \ d {3} 8 \ d ).
Can I write a zero-width assertion?
Php code:
$ Str = '1970 13141078884 13161143334 13263362224 18511925554 18612623450 13141102288 13161146662 13263370884 18513608884 18612625555 13141108580 13161146667 13263389994 13264459992 18600004038 '; // match the last four digits of the mobile phone number. At least one of the four digits is 8preg_match_all ('/???????? /', $ Str, $ res); var_dump ($ res );
Reply content:
I have a set of mobile phone numbers: '2017 13141078884 13161143334 13263362224 18511925554 18612623450 13141102288 13161146662 13263370884 18513608884 18612625555 13141108580 13161146667 100'. The last four matched mobile phone numbers must contain at least eight, how to Write regular expressions?
Do not make effort. For example, (8 \ d {3} | \ d8 \ d | \ d \ d8 \ d | \ d {3} 8 \ d ).
Can I write a zero-width assertion?
Php code:
$ Str = '1970 13141078884 13161143334 13263362224 18511925554 18612623450 13141102288 13161146662 13263370884 18513608884 18612625555 13141108580 13161146667 13263389994 13264459992 18600004038 '; // match the last four digits of the mobile phone number. At least one of the four digits is 8preg_match_all ('/???????? /', $ Str, $ res); var_dump ($ res );
(? = (.?) {3} 8) (\ d {4 })(? = \ D * 8) (\ d {4 })(?! [^ 8] {4}) (\ d {4}) // inspired by @ chouchang's folding answer
Matching in PHP Testing
$ Str = '1970 13141078884 13161143334 13263362224 18511925554 18612623450 13141102288 13161146662 13263370884 18513608884 18612625555 13141108580 13161146667 13263389994 13264459992 18600004038 '; // match the last four digits of the mobile phone number. At least one of the four digits is 8preg_match_all ('/\ d {7 }(? = (.?) {3} 8) (\ d {4})/', $ str, $ res); var_dump ($ res );
/8(?:\d{0,3})$/
Ensure 11 digits:
/^ (? = \ D {11 })(? = \ D * 8 \ d {0, 3}). * $ // there is still no way to do it. I hope other people can come up with it.
I thought too much, so I should write it like this:
/^(?=\d*8\d{0,3})\d{11}$/
/[^ 8] {4} $/