我正在使用這個正則運算式來檢測 10 位數的電話號碼:
/[0-9]{10}|[0-9]{3}.[0-9]{7}/gs
它檢測到以下內容:050-1231231 和 0501231231 甚至:050
1231231
我想檢測這個數字,即使它跨越 10 行,如下所示:
0
5
0
1
2
3
1
2
3
1
uj5u.com熱心網友回復:
利用
/\d(?:\W*\d){9}/g
請參閱正則運算式證明。
筆記
如果電話號碼的意思是替換\W為[- ()\s],和/或添加您在電話號碼中看到的任何其他字符。
解釋
--------------------------------------------------------------------------------
\d digits (0-9)
--------------------------------------------------------------------------------
(?: group, but do not capture (9 times):
--------------------------------------------------------------------------------
\W* non-word characters (all but a-z, A-Z, 0-
9, _) (0 or more times (matching the
most amount possible))
--------------------------------------------------------------------------------
\d digits (0-9)
--------------------------------------------------------------------------------
){9} end of grouping
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/408173.html
標籤:
