I am using the following expression in regex101 with PERL marked up. It works. But it does not work in python with re.
pattern = [0-9]{1,4}+(?![\.\/\-][A-Za-z]{2,})[A-Za-z]
What I am looking for is to catch numbers followed by a letter but NOT numbers followed by more than a letter.
Explanation:
- [0-9]{1,4}+ digits up to 4 with a possessive quantifier
- (?![./-][A-Za-z]{2,})negative look ahead: Which are not followed by 2 or more letters
- [A-Za-z] a letter
All fine, but this is marking up PERL in the regex101 website, as soon as I mark python:
The possessive + symbol is not recognize.
One option is to resort to the library regex: https://pypi.org/project/regex/
but this is an suboptimal solution since re is part of the standard package.
Is there anyway to reproduce this + behavior in normal python regex (re)?
thanks
EDIT: To be clear, this other regex DOES NOT SOLVE THE PROBLEM:
pattern2="[0-9]{1,4}[A-Za-z](?![A-Za-z]{2,})"
because it catches a number and the first letter, what I want if that the regex gives me nothing if the number is followed by more than one letter.