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

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -