在线求一正则表达式.解决方案

WBOY
Release: 2016-06-13 13:39:10
Original
920 people have browsed it

在线求一正则表达式.

,有这么一些字符串.

BS0001/BK0003,或者 BK00006,或者 BK00006/BBM0009/DDK0003


如果有斜杠,要返回斜杠前的内容,没有就是本身.

以上三个返回.
BS0001,BK00006,BK00006


求一正则表达来实现

------解决方案--------------------

PHP code
$s='BS0001/BK0003,或者 BK00006,或者 BK00006/BBM0009/DDK0003';
preg_match_all('#([^/\s]+?)/#s',$s,$m);
print_r($m[1]);

/*
Array
(
    [0] => BS0001
    [1] => BK00006
    [2] => BBM0009
)
*/
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
PHP code

$str    = "BS0001/BK0003,或者 BK00006,或者 BK00006/BBM0009/DDK0003";
echo    preg_replace("/.*?\b([\w]{6,})[\w\/]*/i", "\\1,", $str);

//BS0001,BK00006,BK00006, <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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!