首页 > 解决方案 > 为php结合两个正则表达式

问题描述

我有这两个正则表达式

^(((98)|(\+98)|(0098)|0)(9){1}[0-9]{9})+$
^(9){1}[0-9]{9}+$

如何将这些短语组合在一起?

有效电话:

just start with : 0098 , +98 , 98 , 09 and 9
sample :
00989151855454
+989151855454
989151855454
09151855454
9151855454

标签: phpregex

解决方案


你还没有提供什么通过和什么不通过,但我认为如果我理解正确的话,这将起作用......

/^\+?0{0,2}98?/

现场演示

^         Matches the start of the string
\+?       Matches 0 or 1 plus symbols (the backslash is to escape)
0{0,2}    Matches between 0 and 2 (0, 1, and 2) of the 0 character
9         Matches a literal 9
8?        Matches 0 or 1 of the literal 8 characters

推荐阅读