Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是正则表达式的新手,我尝试了 preg_match 并且结果应该显示hello,但没有发生。
hello
$action3 = "(414)-4204"; if(preg_match('%^(\d{3})+-\d{4}$%',$action3)) { echo "hello"; } else { echo "goodbye"; }
我哪里做错了?
您需要用反斜杠转义括号。它们是正则表达式中的特殊字符。
preg_match('%^\(\d{3}\)+-\d{4}$%',$action3)