Click here to Skip to main content
15,888,270 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
9.8 or 12.09
// one or 2 digits before point and after point
Posted
Comments
MT_ 2-Nov-12 1:36am    
Did any of the solution solved your problem or not ? If it is solved, mark the answer as solution/upvote.

the regex pattern for this would be simple

C#
\d{1,2}.\d{1,2}


seems you are holding it in a string, you need to add \b at start and end as updated below.

I have tried following code and it worked as expected

C#
string STR = "10.01,11.11,111.11,1.1,1.11,222.222,22.222";
string[] lines = STR.Split(',');
Regex regex = new Regex(@"\b\d{1,2}\.\d{1,2}\b");
foreach (string line in lines)
{
    Match match = regex.Match(line.Trim());
    if (match.Success)
    {
        Console.WriteLine(line);
    }
}


Hope that helps. If it does, mark the answer as solution and/or upvote.
-Milind
 
Share this answer
 
v3
Comments
zeshanazam 1-Nov-12 6:27am    
it is not working..
Richard MacCutchan 1-Nov-12 6:35am    
What is not working? Please do not expect people to guess what is happening on your machine.
MT_ 1-Nov-12 6:45am    
There is no reason for it not to work ! If you want regex for xx.yy pattern where xx and yy is digit and it can be 1 or 2 after and beofre the . then this is the pattern for it. Do write in details to enable us to help.
Pete O'Hanlon 1-Nov-12 7:52am    
For the OP - the big difference here is not just the \b character, it's the \. In the original solution, the character was . which means match any character, so 12.22 and 123 would both match.
MT_ 1-Nov-12 8:05am    
Yes. it must be escaped. Missed in first post. However, without \b and \b, it was giving xxx.yyy also as match. Probably I am missing something.
You might want to try this one:
C#
\b(?:\d{1,2}\.+\d{1,2})\b
 
Share this answer
 
v2

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