[Solved] how to write regular expression makes sure that there is no digits after


[*]

Use a negative lookahead assertion:

r'\b[a-z][*]{2}1(?!\d)'

The (?!...) part is the lookahead; it states that it cannot match at any location where a digit (\d) follows.

Regex101 demo; note how only the second line is matched (blue).

Python demo:

>>> import re
>>> pattern = re.compile(r'\b[a-z][*]{2}1(?!\d)')
>>> pattern.search('x**1')
<_sre.SRE_Match object at 0x10869f1d0>
>>> pattern.search('x**10') is None
True
>>> pattern.search('x**10') is None

[*]

solved how to write regular expression makes sure that there is no digits after