regex - lookbehind for start of string or a character -
the command
re.compile(ur"(?<=,| |^)(?:next to|near|beside|opp).+?(?=,|$)", re.ignorecase) throws a
sre_constants.error: look-behind requires fixed-width pattern
error in program regex101 shows fine.
what i'm trying here match landmarks addresses (each address in separate string) like:
- "opp foobar, foocity" --> must match "opp foobar"
- "fooplace, near barplace, barcity" --> must match "near barplace"
- "fooplace, shoppers stop, foocity"--> must match nothing
- "fooplace, opp barplace"--> must match "opp barplace"
the lookbehind avoid matching words opp in them (like in string 3).
why error thrown? there alternative i'm looking for?
re.compile(ur"(?:^|(?<=[, ]))(?:next to|near|beside|opp).+?(?=,|$)", re.ignorecase) you can club 3 conditions using [] , |.see demo.
Comments
Post a Comment