s1='haha "h1" "hi"'
s2='haha "h1" "hi hi"'
I want to get "hi" from s1 ,and "hi hi" from s2.
>>> re.search('".*"$',s1).group()
'"h1" "hi"'
>>> re.search('".*"$',s2).group()
'"h1" "hi hi"'
>>> re.search('"*?.*"$',s1).group()
'haha "h1" "hi"'
>>> re.search('"*?.*"$',s2).group()
'haha "h1" "hi hi"'
Just capture everything that is not " between ":
>>> re.search('"[^"]*"$',s1).group()
'"hi"'
>>> re.search('"[^"]*"$',s2).group()
'"hi hi"'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With