正则表达式。我究竟做错了什么? [英] REGEX. What am I doing wrong?

查看:77
本文介绍了正则表达式。我究竟做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我需要创建一个仅接受电话号码的REGEX。


电话号码始终以261,21开始,96或91,之后有7个
的数字。


类似的东西。 261 1223346,21 2334456等


我尝试了以下但是它不起作用:

^(?:261 | 21 | 96 | 91) \\\ {7} $


我该怎么做?


谢谢,


Miguel

Hello,

I need to create a REGEX which accepts only phone numbers.

The phone numbers start allways with 261, 21, 96 or 91 and have 7
numbers after it.

Something like. 261 1223346, 21 2334456, etc.

I tried the following but it is not working:
^(?:261|21|96|91)\s\d{7}$

How can I do this?

Thanks,

Miguel

推荐答案




我该怎么办?


谢谢,


Miguel



How can I do this?

Thanks,

Miguel


2月26日,2:晚上11点,shapper < mdmo ... @ gmail.comwrote:
On Feb 26, 2:11 pm, "shapper" <mdmo...@gmail.comwrote:

您好,


我需要创建一个仅接受的REGEX电话号码。


电话号码始终以261,21,96或91开头,之后有7个

号码。

类似的东西。 261 1223346,21 2334456等


我尝试了以下但是它不起作用:

^(?:261 | 21 | 96 | 91) \\\\ {7}
Hello,

I need to create a REGEX which accepts only phone numbers.

The phone numbers start allways with 261, 21, 96 or 91 and have 7
numbers after it.

Something like. 261 1223346, 21 2334456, etc.

I tried the following but it is not working:
^(?:261|21|96|91)\s\d{7}





如果(?:)表示非捕获组,则需要括号


^?:( 261 | 21 | 96 | 91)\\\ {7}

if (?:) means a noncapturing group then you need a parenthesis

^?:(261|21|96|91)\s\d{7}


这篇关于正则表达式。我究竟做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆