我需要一些帮助来理解一点正则表达式。我见过这样正则表达式帮助
preg_match("/^
(1[-\s.])? # optional '1-', '1.' or '1'
(\()? # optional opening parenthesis
\d{3} # the area code
(?(2) \)) # if there was opening parenthesis, close it
[-\s.]? # followed by '-' or '.' or space
\d{3} # first 3 digits
[-\s.]? # followed by '-' or '.' or space
\d{4} # last 4 digits
$/x",$number)
我都明白,但不明白如何(?(2) \))
真正的工作......西隧呢代码?和(2)代表。
问题更新...
我读你的答案..当我改变像
preg_match("/^
(1[-\s.])? # optional '1-', '1.' or '1'
\d{3} # the area code
(\()? # optional opening parenthesis
(?(3) \)) # if there was opening parenthesis, close it
[-\s.]? # followed by '-' or '.' or space
\d{3} # first 3 digits
[-\s.]? # followed by '-' or '.' or space
\d{4} # last 4 digits
$/x",$number)
我得到错误,如
Compilation failed: reference to non-existent subpattern
代码是有anythign毛病码?
看到我的问题更新.. – Hacker 2011-05-09 05:13:59
@pradeep更好地应用'前瞻'和'看后面'**声明** – diEcho 2011-05-09 05:20:43
@pradeep我更新我的答案与PHP ..的链接,这将确保有助于你理解你正在谈论的概念 – diEcho 2011-05-09 05:25:14