Home > Backend Development > PHP Tutorial > 求高难度正则解决方法

求高难度正则解决方法

WBOY
Release: 2016-06-13 13:43:29
Original
1181 people have browsed it

求高难度正则
一段话,如:
@abc falieurisdlfalsjdfj Email: abc@abc.cn alkjdiruasjdflasdfj @abc.uk salkdjfoawuierj @123,lskdufasjidfja

上面这段话中 读取@abc 和 @abc.uk 和@123 而不要取出 abc@abc.cn中的 @abc.cn 就像微博中一样 @符号后面,逗号或者句号前面的内容取出来,但是不要涉及到邮箱中的@后面的东西。




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

PHP code
$s = <font color="#e78608">------解决方案--------------------</font><br>
田心老师的没有考虑到  abc@abc.cn这种情况。<br>刚学习正则,来个。<br><br>
Copy after login
PHP code
<?php $str = "@abc falieurisdlfalsjdfj Email: abc@abc.cn alkjdiruasjdflasdfj @abc.uk salkdjfoawuierj @123,lskdufasjidfja";
preg_match_all("/(^|\s *)@([\w.]+)/is",$str,$arr);
print_r($arr); <div class="clear">
                 
              
              
        
            
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