I have this code
String RateBuy7 = Regex.Match(Response, @"</a></td><td>([0-9] \. [0-9] )</td><td>").Groups[1].Value;
I need to find a number that could be like int ("12") and be like double ("12.5"). How to do it right?
Because that code ([0-9] \. [0-9] )
have only found float numbers. But those numbers aren't always float. Help me please//
CodePudding user response:
To match integers as well as "rational numbers" you could use this code:
</a></td><td>([0-9] \.? [0-9] )</td><td>
Notice the question mark behind the dot. This way the dot is needed zero or once for matching.
I can recommend https://regex101.com for testing.
CodePudding user response:
Normally you want something that does HTML parsing for you, but if you are going to have to use a regex, something like this should work:
</a></td><td>\d (\.\d )?</td><td>
https://regex101.com/r/aNHbw8/2
You want that first set of numbers, and then optionally a period followed by some numbers. This should do the trick.