Say if I have an initial string that could contain either an integer or a double, followed by a timescale. Eg, it could be 5.5hours or 30 mins, etc. The data I will be receiving in this format is notoriously none uniformed so, for example, I could receive data such as 5.5 hours. With the added full stop.
I wanted a way to extract an integer or double from such strings, however I am struggling with the possible inclusion of additional full stops/periods. I can easily isolate the numbers and fullstops by replacing the letters with emptyspace.
Can anybody please advise.
Thanks.
should match your criteria:
So, to iterate over all matches in your string:
This regex will not match numbers in exponential notation like
1.05E-6, obviously.If you also want to catch the following timescale, then you can use
Now, after a match,
matchResults.Groups[1]will contain the number.matchResults.Groups[2]will contain the word following the number which you can then check against your list of allowed words. This word is mandatory, i. e. if it’s missing, the entire regex will fail – if you don’t want that, add a?at the end.