Regex 我需要一个用于数字、空格和特殊字符的正则表达式
我需要一个用于数字、空格和特殊字符的正则表达式。以下是我的例子:Regex 我需要一个用于数字、空格和特殊字符的正则表达式,regex,Regex,我需要一个用于数字、空格和特殊字符的正则表达式。以下是我的例子: +44161999888 01144(161)999 8888 1-408-999 8888 +1(408)999 8888 2228888 1-212-222 8888 +1(212)2228888 +1212998888 001(212)999 8888 0161 999 8888 +44(161)999 8888 22228888 01-22228888 +441-22228888 +91-80-26584050 26584
+44161999888
01144(161)999 8888
1-408-999 8888
+1(408)999 8888
2228888
1-212-222 8888
+1(212)2228888
+1212998888
001(212)999 8888
0161 999 8888
+44(161)999 8888
22228888
01-22228888
+441-22228888
+91-80-26584050
26584050
试试这个:
^[0-9 ()\+\-]+$
[]表示该集合中的项目
末尾的+表示其中的一个或多个
0-9表示此范围内的数字
空格表示空格字符
(和)表示括号中的字符
加号和-表示加号和减号
开头的^和结尾的$表示这是从头到尾的完整语句,中间没有其他内容
我想这涵盖了你的整套试试这个:
^[0-9 ()\+\-]+$
[]表示该集合中的项目
末尾的+表示其中的一个或多个
0-9表示此范围内的数字
空格表示空格字符
(和)表示括号中的字符
加号和-表示加号和减号
开头的^和结尾的$表示这是从头到尾的完整语句,中间没有其他内容
我认为这涵盖了您的完整设置,例如在php中:
<?php
$input = "+44 161 999 8888";
//$input = "011 44 (161) 999 8888";
//$input = "1-408-999 8888";
//$input = "+1 (408) 999 8888";
//$input = "222 8888";
//$input = "0161 999 8888";
//$input = "01-2222 8888";
//$input = "+44 1-2222 8888";
//$input = "+91-80-26584050";
//$input = "26584050";
preg_match("/(^\+[0-9]+\ [0-9]+\ [0-9]+\ [0-9]+$|^[0-9]+\ [0-9]+\ \([0-9]+\)\ [0-9]+\ [0-9]+$|^[0-9]+\-[0-9]+\-[0-9]+\ [0-9]+$|^\+?[0-9]+\ \([0-9]+\)\ [0-9]+\ [0-9]+$|^[0-9]+\ [0-9]+$|^[0-9]+\ [0-9]+\ [0-9]+$|^[0-9]+\-[0-9]+\ [0-9]+$|^[0-9]+\ [0-9]+\-[0-9]+\ [0-9]+$|^\+[0-9]+\-[0-9]+\-[0-9]+$|^\+[0-9]+\ [0-9]+\-[0-9]+\ [0-9]+$|^[0-9]+$)/", $input, $m);
echo $input;
print_r($m);
如果您需要数字的特定长度,请将“+”更改为{number},例如长度为4个字符{4}
[0-9]{4}
例如,在php中:
<?php
$input = "+44 161 999 8888";
//$input = "011 44 (161) 999 8888";
//$input = "1-408-999 8888";
//$input = "+1 (408) 999 8888";
//$input = "222 8888";
//$input = "0161 999 8888";
//$input = "01-2222 8888";
//$input = "+44 1-2222 8888";
//$input = "+91-80-26584050";
//$input = "26584050";
preg_match("/(^\+[0-9]+\ [0-9]+\ [0-9]+\ [0-9]+$|^[0-9]+\ [0-9]+\ \([0-9]+\)\ [0-9]+\ [0-9]+$|^[0-9]+\-[0-9]+\-[0-9]+\ [0-9]+$|^\+?[0-9]+\ \([0-9]+\)\ [0-9]+\ [0-9]+$|^[0-9]+\ [0-9]+$|^[0-9]+\ [0-9]+\ [0-9]+$|^[0-9]+\-[0-9]+\ [0-9]+$|^[0-9]+\ [0-9]+\-[0-9]+\ [0-9]+$|^\+[0-9]+\-[0-9]+\-[0-9]+$|^\+[0-9]+\ [0-9]+\-[0-9]+\ [0-9]+$|^[0-9]+$)/", $input, $m);
echo $input;
print_r($m);
如果您需要数字的特定长度,请将“+”更改为{number},例如长度为4个字符{4}
[0-9]{4}
我需要传真号码正则表达式,但总的来说,这是一个巨大的模式数量相匹配。你试过什么了吗?是的,我试了一个小时。我不是Regex的专家,我需要传真号码Regex,但总的来说,这是一个巨大的模式匹配数量。你试过什么了吗?是的,我试了一个小时。我不是regexThank You的专家,但我不需要字母(a-z或a-z)。啊,我明白了。我已经更新了答案,所以现在只有你感兴趣的字符会匹配。谢谢你,但我不需要字母(a-z或a-z)。啊,我明白了。我已经更新了答案,所以现在只有您感兴趣的字符将匹配。