For example, I define "keyword foo near start of string" as this regex:
(?<=^.{,10})foo
And I define "short string" as this regex (or equivalently, 30 chars or less):
^(?=.{,30}$)
Now the question is, I want to match "keyword foo near start of a short string" with one single regex, but am unsure how to do it. The matched text must be "foo" so surrounding text are supposed to be handled properly (with lookarounds).
This one is what I've tried and it obviously doesn't work:
^(?=.{0,30)$)(?<=^.{,10})foo
This one works but matches too much text, I only want foo, not aafoo:
^(?=.{0,30)$).{,10}foo
Expected inputs and outputs:
aaaaaaaaaaa => None
aafooaaaaaa => "foo" (at position 2-5)
aaaaaaaaaaafoo => None (Too far from start of string)
aafooaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa => None (String too long)
I'm using a 3rd-party PyPI package regex (not the built-in re) on Python 3.