I want to extract the number sandwiched between two specific letters.
e.g. string: x23y4z90
I specify x and y , I get 23
I specify y and z , I get 4
I specify z and x , I get 90 (the string pattern loops)
x\dy
yields x23y
, but I don't want the letters included.
*note: This is to read sensor values serially in LabVIEW.
One possibility is to use groups:
x(\d+)y
Now, the second group will contain only the number. The first group will be the whole match.
Another possibility is to use positive lookahead and positive lookbehind:
(?<=x)\d+(?=y)
Please note the +
I added. This is necessary to match numbers with multiple digits.
Check it here for x and y and here for y and z.