我需要一些幫助來理解一點正則表達式。我見過這樣正則表達式幫助
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