正则匹配

WBOY
Release: 2016-06-13 13:48:58
Original
863 people have browsed it

求一个正则匹配

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$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);

Copy after login

得到结果:
XML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
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] => 
        )

)

Copy after login


现在如果$s = 'D ETC56-542NA1210756542N31036 3ZA0C0154',这个正则的表达式 preg_match_all('/([a-zA-Z0-9]\w{1})([\w|-]{10})\w\d(\d{4})|\w{5} \w{5}/')就不对了。求既能满足‘E3ETC56-542NA1220156542N31036 3ZA0C0331’,又能‘D ETC56-542NA1210756542N31036 3ZA0C0154’结果的表达式。

------解决方案--------------------
$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);
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template