For example if the text is 'SetVariable "a" "b" "c"' I need to extract both text with quotation ["a","b","c"] and SetVariable. I found the regex to extract text within quotation marks. I need help on how to extract the rest of text
Asked
Active
Viewed 25 times
0
-
python `re` package offers regex utility. Use something like the pattern in accepted answer here : https://stackoverflow.com/questions/171480/regex-grabbing-values-between-quotation-marks – Bijay Regmi Mar 22 '22 at 11:33
2 Answers
1
A simple version:
x = 'SetVariable "a" "b" "c"'
s = x.split()
spl = [i for i in s]
print(spl)
Output:
['SetVariable', '"a"', '"b"', '"c"']
Using Comprehension:
spl = [i for i in x.split()]
print(spl)
Output:
['SetVariable', '"a"', '"b"', '"c"']

Anand Gautam
- 2,018
- 1
- 3
- 8
0
It seems like you want to parse a command line. shlex
module can do this for you.
import shlex
x = 'SetVariable "a" "b" "c"'
shlex.split(x)
Result:
['SetVariable', 'a', 'b', 'c']

user107511
- 772
- 3
- 23