# Python re Regular Expression (Regex) Positive Look Behind

**URL:** <https://forum.inductiveautomation.com/t/python-re-regular-expression-regex-positive-look-behind/61680>\
**Category:** Ignition\
**Tags:** python, ignition81, scripting\
**Created:** [July 8, 2022, 2:43pm UTC](https://forum.inductiveautomation.com/t/python-re-regular-expression-regex-positive-look-behind/61680 "2022-07-08T14:43:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trent\_Derr](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@Trent\_Derr](https://forum.inductiveautomation.com/u/Trent_Derr)\
**Post date:** [July 8, 2022, 2:43pm UTC](https://forum.inductiveautomation.com/t/python-re-regular-expression-regex-positive-look-behind/61680/1 "2022-07-08T14:43:27Z")

</div>

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’.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/c/8c8908146c6346536f2d11c10849bfb6bf31b81f.png)

However, when I run this same expression and string in ignition I get no matches:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/9/f994f08385edf27b6b6433ba75198fb934210615.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 8, 2022, 3:11pm UTC](https://forum.inductiveautomation.com/t/python-re-regular-expression-regex-positive-look-behind/61680/2 "2022-07-08T15:11:09Z")

</div>

re.match() looks at the begnning of the string for the match. Try using re.search() or re.findall() instead.

```python
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:

```auto
['01']
Found: 01

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 8, 2022, 3:13pm UTC](https://forum.inductiveautomation.com/t/python-re-regular-expression-regex-positive-look-behind/61680/3 "2022-07-08T15:13:54Z")

</div>

The difference between `re.search` and `re.match` has bitten me _many_ times.

---

<div class="post-metadata">

**Author:** ![Trent\_Derr](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@Trent\_Derr](https://forum.inductiveautomation.com/u/Trent_Derr)\
**Post date:** [July 8, 2022, 3:27pm UTC](https://forum.inductiveautomation.com/t/python-re-regular-expression-regex-positive-look-behind/61680/4 "2022-07-08T15:27:06Z")

</div>

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!
