Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to match Patterns Starts With 9838/9839/9918/9919

and followed by these patterns(these are mobile numbers)
starting digits like 9839 and last 6 digits like below patterns


XXYYAB AXXYYZ AXYZ00 AXXXYZ ABXXYY AXYYYZ AXXXXY
337719 733119 912300 522238 295588 257772 488886


I used Regular Expression 9839([0-9])\1{3} this regex matching 9839AXXXXZ but it also returning 5 times matched digits like 9839555559


For Example Mobile Numbers-
9839337719-XXYYAB
9839733119-AXXYYZ
9839912300-AXYZ00
9839522238-AXXXYZ
9839295588-ABXXYY
9839257772-AXYYYZ
9839488886-AXXXXY

I'm stuck please help me out guys
thanks in advance
Posted
Updated 12-Dec-14 0:40am
v2
Comments
TheRealSteveJudge 5-Dec-14 3:38am    
Unfortunately unclear.
Can you give some examples of input data
and tell us what you want to extract or match?
Surendra0x2 5-Dec-14 3:53am    
like Mobile Number Starts With 9839 and Rest 6 Digits are AXXXXY means 9839255556 here 5 repeating 4 times I want to build a regular expression it and search in database matching regular expression like this.
Marcin Kozub 5-Dec-14 3:47am    
There is very usefull tool for testing regular expressions and it can be used for free: http://www.ultrapico.com/expresso.htm
PeejayAdams 5-Dec-14 7:19am    
9839([0-9])\1{3}(?!\1)

would stop the next character being a repeat of the previous group by using a negative backreference but you'd need a separate check for the string being all numeric.

I suspect that someone out there will know how to combine both checks into a single regex.

1 solution

As per i understand you well, the regex pattern should look like: ^(9838|9839|9918|9919)\d{6}\-\w{6}$* with mulitline option set to true.
I tested it on:
9839337719-XXYYAB
9839733119-AXXYYZ
9839912300-AXYZ00
9838488886-AUXXXU
9839522238-AXXXYZ
9839295588-ABXXYY
9949488886-AUXXXY
9839257772-AXYYYZ
9839488886-AXXXXY
9859488886-AXXXXY

It returns 8 records fulfilling criteria (the last one is ignored).
 
Share this answer
 
Comments
Surendra0x2 13-Dec-14 3:38am    
Sir it is for c#?when i applied in c# its not returning any matched results..
Maciej Los 13-Dec-14 4:18am    
I tested it using RegexDesigner.

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