Regular Expression Matching

Source: Internet
Author: User
Find a regular match PHPcode $ s = 'e3etc56-542NA1220156542N310363ZA0C0331 '; preg_match_all ('/([a-zA-Z0-9] \ w {1}) ([\ w |-] {10 }) \ w \ d (\ d {4}) | \ w {5} \ w find a regular match
PHP code
  $s = 'E3ETC56-542NA1220156542N31036 3ZA0C0331';preg_match_all('/([a-zA-Z0-9]\w{1})([\w|-]{10})\w\d(\d{4})|\w{5} \w{5}/', $s, $r);print_r($r);

Expected result:
XML code
  Array(    [0] => Array        (            [0] => E3ETC56-542NA12201            [1] => 31036 3ZA0C        )    [1] => Array        (            [0] => E3            [1] =>         )    [2] => Array        (            [0] => ETC56-542N            [1] =>         )    [3] => Array        (            [0] => 2201            [1] =>         ))


If $ s = 'd ETC56-542NA1210756542N31036 3ZA0C0154 ', this regular expression preg_match_all ('/([a-zA-Z0-9] \ w {1}) ([\ w |-] {10 }) \ w \ d (\ d {4}) | \ w {5} \ w {5}/') is incorrect. The expression that can satisfy 'e3etc56-542NA1220156542N31036 3ZA0C0331 'and 'd ETC56-542NA1210756542N31036 3ZA0C0154' is obtained.

------ Solution --------------------
$ S = 'e3etc56-542NA1220156542N31036 3ZA0C0331 ';
Preg_match_all ('/([a-zA-Z0-9] [\ w \ s] {1}) ([\ w |-] {10}) \ w \ d (\ d {4 }) | \ w {5} \ w {5}/', $ s, $ r );
Print_r ($ r );

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.