I am trying to extract the text 3.81 pH from the below output. For that, initially wrote a regex (\d+\.\d\d)\s(pH)
.
<ESC>CS3<CR><LF>Date/Time 27-Oct-2022 <CR><LF> 16:01:59 <CR><LF>Sample -- <CR><LF>Status OK <CR><LF> <CR><LF>User Administrato<CR><LF> r <CR><LF> <CR><LF>Method DM <CR><LF> <CR><LF>Meas.type1 DM pH <CR><LF> Sensor MTPHSensor <CR><LF> <CR><LF>Value 3.81 pH <CR><LF> Temp. 23.6 <194><176>C ATC <CR><LF> Endpoint Automatic <CR><LF> (Standard) <CR><LF> <CR><LF> <CR><LF> <CR><LF> <CR><LF> <CR><LF>
However, when I ran the compiler engine (which I am having to use) to test it:
For a few moments, it showed blank in the UI
Then it blinked the value 3.81 ph on the UI (much to my joy) for a few moments
Then agonizingly showed blank again and eventually stopped returning me a blank
From this observation, I hypothesized that the compiler engine must have continued to search for this pattern in the remainder of the text even after it found the first match and that is why it eventually returned with a blank.
I subsequently understood from a few similar threads in Stackoverflow (linked below) that I am probably correct (but not 100% sure and happy to be rectified).
Moreover from these threads, I understood that I need to make the regex lazy (or non-greedy) to ensure the compiler engine stops at the first occurrence it finds the match and returns the matched value (which is what I want it to do).
For that, I have modified the regex now to (\d+?.\d+?)\s(pH)
.
This expression also matches the text 3.81 pH. I checked it on the Regex101 website. But are the placement of the ?
character really correct for what I am trying to do?
Thanks in advance!