I have a readout from a balance which reads like this:
G - 3.56436 mg
I need to use regex (required by application) to provide the numeric value to be later on registered within the application. I am using the following regex with success to some different balance models.
(?<= )(?<Value>[-\d\.]*)\s*(?<Unit>[\w]*)\s*$
Group called 'value' is responsible for capturing the numerical value, and group called 'unit' captures the measurement unit (in milligrams on the example provided).
The challenge I have is, using the regex provided above, because of the two spaces between the "-" and the numerical value, the regex is not capturing the negative symbol as needed, and every attempt to capture the negative symbol I tried so far led me to capture the "-" and the number as separate matches.
What I needed my match to show up was one match equal to "-3.56436", with no spaces between the negative symbol and the number.
I tried taking a look at some options like lookaround, but had no success so far. The closest I got was to report the negative and numeric value on the same match, but it also captured all spaces along with it. Here is the regex that led to this outcome (same as previous one, with addition of "\s" on value group).
(?<= )(?<Value>[-\d\.\s]*)\s*(?<Unit>[\w]*)\s*$
Is this even technically possible using regex alone? Am I asking too much of it and I would need to rethink my strategy?
First post on Stack Overflow, so completely newbie at doing this. Please be patient at the low level of technical expertise.