Python Regex findall But Not Including the conditional string -
i have string:
the quick red fox jumped on lazy brown dog lazy
and wrote regex gives me this:
s = quick red fox jumped on lazy brown dog lazy re.findall(r'[\s\w\s]*?(?=lazy)', ss) which gives me below output:
['the quick red fox jumped on ', '', 'azy brown dog ', '']
but trying output this:
['the quick red fox jumped on ']
which means regex should give me till encounters first lazy instead of last 1 , want use findall.
make pattern non-greedy adding ?:
>>> m = re.search(r'[\s\w\s]*?(?=lazy)', s) # ^ >>> m.group() 'the quick red fox jumped on '
Comments
Post a Comment