简体   繁体   中英

Regex extract everything except a pattern (string in quotes)

I have a string like input = "I really like "Game of Thrones" (show in quotes) and I only want to extract I really like but I can't get the right regex to do this. Something like this doesn't work re.search(".*^(?!\\".*\\")", input) .

I can do something like re.sub('".*"','', input) but I'm struggling to find the non-sub, extract using re.search method.

Here you go:

input = 'I really like "Game of Thrones"'

output = re.sub('"[a-zA-z0-9 _\.]+"','',input)

print(output)

output:

I really like

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM