tags:

views:

79

answers:

6

I want to check if my string holds following value or not.. My condition is

48-57(1 or more time)32(or)10(or)13(then)48(then)32(or)10(or)13(then)111981066060

how to write regular expression for above condition. bracket text indicates occurrence. I tried it but it wont work.Thanks in advance.

Samples:

  • 4850324810111981066060
  • 50104810111981066060
+1  A: 

Check out Expresso - it allows you to build and test your regexs, and creates a C# code snippet or a .NET assembly for you right away. Highly recommended!

marc_s
+1  A: 

(4[8-9]|5[0-7])+(32|10|13)48(32|10|13)111981066060

Amarghosh
+1  A: 
Regex regex = new Regex(@"(?:4[89]|5[0-7])+(?:32|10|13)48(?:32|10|13)111981066060");
regex.Match(string);

Didnt test though!

Paul Creasey
A: 

You can test regular expressions in .NET online using Nregex

Russ Cam
A: 

This this:

(48|49|50|51|52|53|54|55|56|57)+(32|10|13)48(32|10|13)111981066060

EDIT: Just saw Paul answer and this really can be shortened to

(4[89]|5[0-7])+(32|10|13)48(32|10|13)111981066060

Only difference between hos and mine approaches is: he doesn't keeps grouping information (as that isn't required) and I don't care for ignore them.

Rubens Farias
A: 

You can start with the following and see if you need to make imprevements

(4[89]|5[0-7])+(32|10|13)48(32|10|13)111981066060

it might be better to split up into fields and check those fields against your business logic instead of relying on a static regexp like the above.

rsp