使用正则表达式C#匹配3344之类的模式 [英] Match Pattern like 3344 using regular expression C#

查看:99
本文介绍了使用正则表达式C#匹配3344之类的模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有手机号码 -

Suppose i have mobile numbers like-

9839223345<br />
9839223346<br />
9839223323<br />
9839223321<br />
9839223350<br />
9839223325<br />
9839334428<br />
9839445529<br />





我想制作一个正则表达式来匹配这些模式。



I want to make a regular expression to match these Patterns.

推荐答案

请看我的评论这个问题。



模式:

- 字符集(单词): \w +

- 一组数字: \d +



如需了解更多信息,请参阅:

正则表达式语言 - 快速参考 [ ^ ]

常规表达式示例 [ ^ ]





如果Matt T. Heffron是对的,你正在寻找一种方式为了找到连续的重复,我建议使用这种模式:(\d)\1 + +



A更多细节:这里: http://stackoverflow.com/questions/6507982/regex-to-find-repeating-numbers [ ^ ]
Please, see my comment to the question.

Pattern for:
- set of characters (word): \w+
- set of digits: \d+

For further information, please see:
Regular Expression Language - Quick Reference[^]
Regular Expression Examples[^]


If Matt T. Heffron is right and you're looking for a way to find consecutive duplicates i'd suggest this pattern: (\d)\1+

A bit more details: here: http://stackoverflow.com/questions/6507982/regex-to-find-repeating-numbers[^]


我想这就是你想要的:

I think this is what you want:
(\d)\1(\d)\2



查找数字后跟相同的数字,后跟另一个数字(可能相同),后跟第二个数字。

编辑:

如果数字对不能相同,(即2222应该失败),然后你可以添加一个负面的预测,如:


Find a digit followed by the same digit, followed by another digit (possibly the same) followed by the second digit.

If the pairs of digits must NOT be the same, (i.e., 2222 should fail), then you can add a negative look-ahead like:

(\d)\1(?!\1)(\d)\2



您可以使用 Expresso [ ^ ]工具(免费)构建/探索/学习正则表达式。


You can use the Expresso[^] tool (free) to build/explore/learn regular expressions.


这篇关于使用正则表达式C#匹配3344之类的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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