Using regex assertion in python

python, regex

Solution

Convert it to Non-capturing group and get the matched group from index 1.

(?:\d+\w+\d+)(\w+\b)

here is DEMO

If you are interested in `[a-z]` only then change `\w` to `[a-z]` in above regex pattern. Here `\b` is added to assert position at a word boundary.

sample code:

import re
p = re.compile(ur'(?:\d+\w+\d+)(\w+\b)', re.IGNORECASE)
test_str = u"123abc456someword 0001abde19999anotherword"

re.findall(p, test_str)

Problem

I am experimenting with regex and i have read up on assertions a bit and seen examples but for some reason I can not get this to work.. I am trying to get the word after the following pattern using look-behind. ``` import re s = '123abc456someword 0001abde19999anotherword' re.findall(r'(?<=\d+[a-z]+\d+)[a-z]+', s, re.I) ``` The results should be `someword` and `anotherword` But i get `error: look-behind requires fixed-width pattern` Any help appreciated.

Original source