Regular match phone number four bit at least one is 8? How to write?

Source: Internet
Author: User
I have a cell phone number: ' 13141078884 13161143334 13263362224 18511925554 18612623450 13141102288 13161146662 13263370884 18513608884 18612625555 13141108580 13161146667 13263389994 13264459992 18600004038 18612932226 ', match the next four digits at least one is 8 mobile phone number, how to write it?
Don't be too poor to lift. such as (8\d{3}|\d8\d\d|\d\d8\d|\d{3}8\d).
0 Wide assertion can write?

PHP Code:

$str = '13141078884 13161143334 13263362224 18511925554 18612623450 13141102288 13161146662 13263370884 18513608884 18612625555 13141108580 13161146667 13263389994 13264459992 18600004038 18612932226';// 匹配手机号后四位至少有一个是8preg_match_all('/????????/', $str, $res);var_dump($res);

Reply content:

I have a cell phone number: ' 13141078884 13161143334 13263362224 18511925554 18612623450 13141102288 13161146662 13263370884 18513608884 18612625555 13141108580 13161146667 13263389994 13264459992 18600004038 18612932226 ', match the next four digits at least one is 8 mobile phone number, how to write it?
Don't be too poor to lift. such as (8\d{3}|\d8\d\d|\d\d8\d|\d{3}8\d).
0 Wide assertion can write?

PHP Code:

$str = '13141078884 13161143334 13263362224 18511925554 18612623450 13141102288 13161146662 13263370884 18513608884 18612625555 13141108580 13161146667 13263389994 13264459992 18600004038 18612932226';// 匹配手机号后四位至少有一个是8preg_match_all('/????????/', $str, $res);var_dump($res);

(?=(.?){3}8)(\d{4})(?=\d*8)(\d{4})(?![^8]{4})(\d{4})  // 受@chouchang折叠答案的启发

PHP tests can match

$str = '13141078884 13161143334 13263362224 18511925554 18612623450 13141102288 13161146662 13263370884 18513608884 18612625555 13141108580 13161146667 13263389994 13264459992 18600004038 18612932226';// 匹配手机号后四位至少有一个是8preg_match_all('/\d{7}(?=(.?){3}8)(\d{4})/', $str, $res);var_dump($res);

/8(?:\d{0,3})$/

Guaranteed 11 Digits:

/^(?=\d{11})(?=\d*8\d{0,3}).*$///还是没有办法,期待其他人能想出来

I think so much, I should write:

/^(?=\d*8\d{0,3})\d{11}$/

/[^8]{4}$/

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.