Hello,
I’m struggling with regex (re) expression in ignition. The expression works in a regex tester, but does not work in ignition. The weird thing is that only the negative lookbehind is not working. I have other regular expression matches and they are working as normal.
Here is a snapshot of my expression functioning in a regex test environment. It successfully matches the two digits after ‘TDY’.

However, when I run this same expression and string in ignition I get no matches:

re.match() looks at the begnning of the string for the match. Try using re.search() or re.findall() instead.
import re
pattern = r'(?<=TDY)[0-9][1-9]'
stringIn = '/XYZ01/TDY01/L01'
# using re.findall
print re.findall(pattern, stringIn)
# using re.search
search = re.search(pattern, stringIn)
if search:
print 'Found:', search.group()
else:
print 'Not found'
output:
['01']
Found: 01
2 Likes
The difference between re.search
and re.match
has bitten me many times.
2 Likes
Ah thank you @JordanCClark. That solved my problem. I guess I just assumed that a match would work since I was getting the result I was looking with the online tester while having the match function selected.
Thank you for the quick help!
1 Like