Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Updated 14-Dec-14 20:10pm
v2
Comments
Maciej Los 15-Dec-14 1:50am    
I do not see AABB in a set of digits ;(
Surendra0x2 15-Dec-14 1:57am    
sir suppose i want to match mobile numbers containing patter aabb-2233 means all possible combinations 1122 or 3344 or 5566
Maciej Los 15-Dec-14 2:03am    
Possible combinations of what?
Please, provide example input and expected output.
Not clear.
Matt T Heffron 16-Dec-14 13:01pm    
Do either of the solutions below solve your issue?
If so, please formally "Accept the solution(s)".
If not, can you provide more clarification of the question (use the "Improve question" above)?

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[^]

[EDIT]
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[^]
 
Share this answer
 
v3
Comments
Matt T Heffron 15-Dec-14 14:42pm    
I think OP is looking for consecutive pairs of duplicate digits.
Maciej Los 15-Dec-14 14:45pm    
We'll see ;)
I think this is what you want:
(\d)\1(\d)\2

Find a digit followed by the same digit, followed by another digit (possibly the same) followed by the second digit.
Edit:
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

You can use the Expresso[^] tool (free) to build/explore/learn regular expressions.
 
Share this answer
 
v2
Comments
Maciej Los 15-Dec-14 14:21pm    
I hope you're right!
+5!
Andreas Gieriet 16-Dec-14 19:11pm    
My 5!
Cheers
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900