Python regular expressions extract the contents of parenthetical quotation marks in multiline strings.

recently learned python regular expressions, want to use regular expressions to extract the specified string in multiple lines

I have been searching the Internet for a long time, and there are a lot of people asking questions on the Internet, but they are all about the one-way situation. Ask the Great God for advice

example:

str = "jh2kn as.12an sss g2gs.Abc ("xxx") asdf;njkasahsda ng2gs.Abc ("yyy")"

extract xxx,yyy between "and"

< hr >

my own test is:

text = "xxx ("https://www.baidu.com/1.pngxxx")"
pattern = r" ^ (. +)? (". + (")) $"

the result: xxx ("https://www.baidu.com/1.pngxxx")
" actually I just want to get: https://www.baidu.com/1.pngxxx

it"s urgent


since you only want the content between double quotes, then group only those inside double quotes.

>>> p= re.compile('.+?"(.+?)"')
>>> p.findall('xxx("https://www.baidu.com/1.pngxxx")')
['https://www.baidu.com/1.pngxxx']
>>> p.findall('jh2kn as.12an sss g2gs.Abc("xxx")asdf;njkasahsda ng2gs.Abc("yyy")')
['xxx', 'yyy']

regular test

regular:

r"\(\"([^\"]*)\"\)"
Menu