简体   繁体   English

正则表达式中带*的电话号码

[英]Regex for phone numbers with * in it

I have created a regex for phone numbers as follows \\\\d+ ?\\\\w{0,9} ?\\\\d+ . 我为电话号码创建了一个正则表达式,如下\\\\d+ ?\\\\w{0,9} ?\\\\d+ Now i have a problem that this only accepts numbers. 现在我有一个问题,它只接受数字。 Sometimes i receive the phone number as starified so it can be 011***1334. 有时我会收到带有星号的电话号码,所以可以是011 *** 1334。 How can i incorporate the stars portion into the above regex expression. 我如何将星号部分合并到上述正则表达式中。

I'm having trouble getting your regex to work in the first place, without stars, 首先,让您的正则表达式无法正常工作是麻烦的,

but anyway... you can represent the star by escaping it. 但无论如何...您可以通过转义代表星星。

\\*

So you should just turn all of your \\d into [\\d\\*] or [\\\\d\\\\*] if you have to escape the \\ first in your java. 因此,如果必须先在Java中转义\\ ,则应将所有\\d变成[\\d\\*][\\\\d\\\\*]

Some regular expression engines don't require you to escape all special characters in [] so I'd watch for that behavior if it doesn't work at first 一些正则表达式引擎不要求您转义[]所有特殊字符,因此,如果一开始它不起作用,我会注意该行为

Anywhere you use \\\\d , turn it into [\\\\d\\\\*] 随时随地使用\\\\d ,将其转换为[\\\\d\\\\*]

[\\d\\*]+ ?\\w{0,9} ?[\\d\\*]+

I agree with Sam I am though; 我同意山姆,但我同意。 the original seems odd. 原来看起来很奇怪。 If you just need numbers and asterisks, this should do (escaped Java-style): 如果只需要数字和星号,则应该这样做(Java样式的转义):

[\\d\\*]{7,10}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM