[英]Regex pattern not identifying pattern
我正在使用正則表達式模式從字符串中提取匹配項
我的模式是:
"^(([^\\.\\-\\,a-wy-z]([\\(]?(\\+|[x])?\\d+[\\)]?)?[\\s\\.\\-\\,]?([\\(\\d[\\)]?)?[\\s\\.\\-\\,]?(\\d+[\\s\\.\\-\\,]?)+[^\\.\\-\\,a-z])|((\\+|[x])?\\d+))$"
我的字符串是
"This is the string +971 987654321 form which +91 9876543210 all the phone number +91 987 654 3210 has to be extracted +91 987 654 3210 and displayed in the +971-98-7654321 logcat and the post office box number is 233227"
但不幸的是,該模式沒有從字符串中識別出任何匹配的模式。 我已經通過意圖操作驗證了“Check RegExp”中的表達式。 這里的模式成功識別了我在字符串中使用的所有電話號碼
任何幫助表示贊賞。
假設您的電話號碼中至少有10
位數字(不包括+
、空格、 -
等),這將起作用
\s+(\+[\d\s-]{10,})\s+
如果您假設,數字和單詞之間不能有空格,那么您可以使用
(\+[\d\s-]{10,})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.