preg_match_all ("/(? (d{3})? )? -? (?(1) [-s] ) d{3}-d{4}/x",
"Call 555-1212 or (221)-(820)-555-1212", $phones);
print_r($phones[0]);echo "
";
print_r($phones[1]);
输出的结果为:
Array ( [0] => 555-1212 [1] => (820)-555-1212 )
Array ( [0] => [1] => 820 )
谁能帮忙解释下这个正则表达式的意思?关键是 (? (d{3})? )? (?(1) [-s] ) 这部分。
为什么能 匹配 (820),却不能匹配 (221) ?
(? (d{3})? )? (?(1) [-s] ) 中
(1) 引用的即 (d{3})
(?(1) [-s] ) 如果 (d{3}) 匹配成功,则继续匹配 [-s]
原型是(?a b|c) ,如果a匹配了,继续匹配b,否则匹配c

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
