Home > Backend Development > PHP Tutorial > 正则有关问题

正则有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 13:34:45
Original
907 people have browsed it

正则问题
两个例子:

86AA4NP4210950SM
86AAUWPB2112507E


求红色部分的结果。

我写的正则:

PHP code
<!--

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

-->preg_match_all('/([a-zA-Z0-9][\w\s]{1}\w{2})\w{2}(\d{4})\w{4}/',$s1,$r1);
print_r($r1);
Copy after login


只能匹配第二个例子。求能同时满足例一例二的正则表达式。




------解决方案--------------------
你这个用什么正则啊,直接substr()多好
PHP code

$stra='86AA4NP4210950SM';
$strb='86AAUWPB2112507E';
$a = substr($stra,2,4);
$b = substr($stra,8,4);
<br><font color="#e78608">------解决方案--------------------</font><br>最啊,不是很规律吗,<br>从第3个字符substr到第6个<br>再从第9个substr到12不就完事了吗 <div class="clear">
                 
              
              
        
            </div>
Copy after login
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