我需要一个以下格式的正则表达式 [英] i need a regular expression for below format

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

问题描述

我需要以下格式的正则表达式



(111)222-3333(仅限10位数)

11122212345(10或11)数字)

111-222-1234(仅限10digits)

解决方案

这些正则表达式将捕获建议的输入



(111)222-3333(仅限10个数字):

 \([0-9] { 3 } \)[0-9] { 3 }  -  [0-9] { 4 } 





11122212345(10或11位数):

< pre lang =c#> [0-9] { 10 11 }





111-222-1234(仅限10个数字):

 [0-9] {  3 }  -  [0-9] { 3 }  -  [0-9] { 4 } 





这将抓住任何给定的例子

 \([0-9] { 3 } \)[0-9] { 3 }  -  [0-9] { 4 } | [0-9] { 10  11  } | [0-9] { 3 }  -  [0-9] { 3 }  -  [0 -9] { 4 } 


试试这个:

使用System; 
使用System.Text.RegularExpressions;

公共课程
{
public static void Main()
{
Regex regex = new Regex(@^ \d {3} -\d {3} -\d {4}

| ^ \(\d {3} \)\d {3} {-\d 4}

i need a regular expression for below format

(111)222-3333 (10digits only)
11122212345 (10 or 11 digits)
111-222-1234 (10digits only)

解决方案

These regular expressions will catch the suggested inputs

(111)222-3333 (10digits only):

\([0-9]{3}\)[0-9]{3}-[0-9]{4}



11122212345 (10 or 11 digits):

[0-9]{10,11}



111-222-1234 (10digits only):

[0-9]{3}-[0-9]{3}-[0-9]{4}



This will catch any of the given examples

\([0-9]{3}\)[0-9]{3}-[0-9]{4}|[0-9]{10,11}|[0-9]{3}-[0-9]{3}-[0-9]{4}


Try this:

using System;
using System.Text.RegularExpressions;

public class Program
{
	public static void Main()
	{
		Regex regex = new Regex(@"^\d{3}-\d{3}-\d{4}


|^\(\d{3}\)\d{3}-\d{4}


这篇关于我需要一个以下格式的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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