Hi. I am working with a long string and extracting certain pieces of information from it, where it is in a static place within the string. I now have an issue where I have some text that can change length.
I need to extract just numbers and the decimal place which I am doing by retrieving the first 25 characters of this section of the string by using the Regex statement of System.Text.RegularExpressions.Regex.Replace(strVolume,“[^/./0-9]”,“”)
My issue is, there can be an additional number within the substring, which gets added to end of the number and makes it incorrect. For example:
464.27856000000000Class 4 gives me 464.278560000000004
431.42171877975682, Row 1 gives me 431.421718779756821
Is there anyway I can alter my regex to ignore “Class” or “, Row” and everything after them?
Edit: This is just to remove the unwanted characters from your input. Don’t forget to use the “matches” method or the matches activity to get the apt result.
@fbxiii apologies, but I wish the post had been a little less ambiguous for people to get the exact requirement.
I see that you’re going with your tweak. However, just to see if it’s clear this time, from this input 464.27856000000000Class 4, you want only 464.27856000000000, right?
If that’s the case, you can give this a shot once: (\d+(.\d+)?)(?=[A-Za-z,-])
This doesn’t even require you to use replace method here. You can directly use this regex in your matches and it will give you the required value “464.27856000000000” from an input like 464.27856000000000Class 4
If this still doesn’t work for you, you can always go with your alternative.