Click here to Skip to main content
15,912,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having a problem with creating a regular expression to parse a Size, except delimited by a comma.

Ex.

34,34 = success
34,34a = fail

I only want a match of two numbers, I've tried the regular expression

Regex.IsMatch(input, "([0-9],[0-9])");"


And almost works, but matches letters succeeding the second pair.

I've looked for examples, but most are in javascript and I've almost sure C#'s regex is different.
I also know there are alternatives to parsing a string into a Size, but I'm striving to find a working regex.

Best regards,

austinbox
Posted

1 solution

JavaScript
Regex.IsMatch(input, "([0-9],[0-9])");

This expression does find a match for [numeric],[numeric] inside a string but does nothing about the rest of the input...
so a1,2,b also considered valid.
You have to include the begin-end marks to tell that you are looking for a pair of numbers separated by comma and nothing more...
JavaScript
Regex.IsMatch(input, "^([0-9],[0-9])$");
 
Share this answer
 
Comments
austinbox 1-Dec-13 1:39am    
Thank you so much, this helps a lot!

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