Reputation: 2901
I want to check if my string holds following value or not:
For samples:
My condition is
48-57(1 or more time)32(or)10(or)13(then)48(then)32(or)10(or)13(then)111981066060
Question: How to write regular expression for above condition. Parenthesis indicate occurrence.
Upvotes: 0
Views: 1085
Reputation: 23383
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.
Upvotes: 0
Reputation: 57996
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.
Upvotes: 0
Reputation: 28894
Regex regex = new Regex(@"(?:4[89]|5[0-7])+(?:32|10|13)48(?:32|10|13)111981066060");
regex.Match(string);
Didnt test though!
Upvotes: 1