I’m stumped as to why this Python regex doesn’t give me the expected results. In the example below, I am expecting the output to be “/w:document/w:body/w:sectPr” but the actual result (Python v3.2) is “/w:sectPr”. I have simplified my problem for the following example.
import re
path = "/w:document/w:body/w:sectPr/w:footerReference"
rxSetting = re.compile('(/\w+:[^/]+){3}') # top-three
matchSetting = rxSetting.match(path)
setting = matchSetting.group(1)
print(setting)
When I check it with regexpal, it matches what I wanted. Do I need to do something
specific in Python to make this work?
Thanks for any advice.
Here try this :
If you want to capture (group) the first three you will need the parenthesis around the whole regex.