'--option1"value1" --option2""spacing"
{
"option1": "value1",
"2 option" : "space writing"
}
I need a code that makes it this way.
The problem here is that if I split based on spacing, there may be an error because there is a space in "", but is there a regular expression or code that can be split based on spacing, ignoring the space in ""?
python regex
If you experiment with regular expressions on the regex101.com site, most of them will be solved.
If we implement it with Python code, it would be as follows.
import re, pprint
text = '--option1 "value1" --option2 "spacing"
match_objects = re.compile(r'--(option\d)\s*\"([^\"]+)\"\s*').findall(text)
match_dicts = {k:v for k, v in match_objects}
pprint.PrettyPrinter(indent=4, width=30).pprint(match_dicts)
But... "Spaced out"The front Two double quotes are correct, right? First of all, I thought "spacing" was the intended example.
© 2024 OneMinuteCode. All rights reserved.