Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract string from between quotations

I want to extract information from user-inputted text. Imagine I input the following:

SetVariables "a" "b" "c" 

How would I extract information between the first set of quotations? Then the second? Then the third?

like image 440
Reznor Avatar asked Jan 16 '10 05:01

Reznor


People also ask

How do you find the string between double quotes?

Use the re. findall() method to extract strings between quotes, e.g. my_list = re. findall(r'"([^"]*)"', my_str) .

How do you escape quotation marks in a string?

You can put a backslash character followed by a quote ( \" or \' ). This is called an escape sequence and Python will remove the backslash, and put just the quote in the string. Here is an example. The backslashes protect the quotes, but are not printed.

How do you split a string with double quotes in Python?

You can escape quotes by preceding them with a \ like so : my_var = "Tabvxc \"avcx\"sdasaf\" sadasfdf. sdsadsaf '0000000000000000000000000000000'."

How do you split quotation marks?

Question marks and exclamation marks go inside the quotation marks when they are part of the original quotation. For split quotations, it's also necessary to add a comma after the first part of the quotation and after the narrative element (just like you would with a declarative quotation).


1 Answers

>>> import re >>> re.findall('"([^"]*)"', 'SetVariables "a" "b" "c" ') ['a', 'b', 'c'] 
like image 97
jspcal Avatar answered Sep 30 '22 00:09

jspcal