正则疑义

WBOY
Release: 2016-06-13 10:36:21
Original
983 people have browsed it

正则疑问
ereg("^a{2,}$","aaasssaaa")
为什么返回false

------解决方案--------------------
建议用 preg_match 这个比ereg 的效率高些。
------解决方案--------------------
汗~~~看错了。
但是你的规则是要求两个以上连续的a,从开头到结束
但是你的字符串中间有其他字符
------解决方案--------------------
ereg("^a{2,}","aaasssaaa")


^a{2,}$ 表示匹配两个及以上由 a 组成的串,而你的 aaasssaaa 不是,里面有字符 s

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

探讨
ereg("^a{2,}","aaasssaaa")


^a{2,}$ 表示匹配两个及以上由 a 组成的串,而你的 aaasssaaa 不是,里面有字符 s

------解决方案--------------------
PHP code
$a = ereg("^a{2,}.*a{2,}$","aaasssaaa");var_dump($a);<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