2012-10-25 50 views

回答

3

由於Java的字符串轉義規則,使用雙反斜槓。純正則表達式的意思是:

\D*? # Match any number of non-digit characters (the "?" is useless here) 
(  # Match... 
\d # a single digit 
\D*? # optionally followed by any number of non-digits (again, useless "?") 
){10} # Repeat the previous group 10 times. 

所以這個表達式包含正好十個數字(外加任意數量的其他非數字字符)的任意字符串匹配。

+0

把我的帽子脫掉給你:) –

0

根據this link正則表達式語法基於Java Platform SE 6 syntax

預定義字符類
...
\ d阿位:[0-9]
\ DA非數字:[^ 0-9]
...

而在有問題的代碼,你從here得到它說

驗證,該電話號碼是(999)999-9999爲墊。這可以通過使用REGEX函數檢查號碼是否具有(999)999-9999格式的十位數字。

請在適用的地方引用您的問題。節省我們去尋找它們

+0

有趣的是,你所援引的評論不能正確解釋正則表達式正在做什麼。 –

+0

@TimPietzcker認爲你會發現操作系統真的在問'正則表達式如何工作'。因此,我甚至不會打擾。 –

0

如果您使用Salesforce示例中的REGEX,則無用。它匹配「this1234567890that」,其中「this」和「that」可以是任何值。我使用:NOT(REGEX(Phone,「\([0-9] {3} \)[0-9] {3} - [0-9] {4} | \ d {10}」))來完成期望的行爲。

我的版本翻譯爲:

\\(  # Match '(' 
[0-9]{3} # Match 3 digits 
\\)  # Match ')' followed by a space 
[0-9]{3} # Match 3 digits 
-  # Match hyphen 
[0-9]{4} # Match 4 more digits 
|\\d{10} # or match 10 digits instead of all the previous