Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to extract the text between " " in Python [closed]

Tags:

python

For instance, how there is a string a, which is defined as

a = "\"hello\""

how to use re extract the text hello?


1 Answers

m = re.search('"([^"]*)"', a)
m.group(1)

The [^"]* says that there must be no " inside the string.

That is important for cases like:

"a" bcd "e"
like image 70
Igor Chubin Avatar answered Mar 29 '26 16:03

Igor Chubin