Mar-02-2022, 05:15 PM
I think a regex could help.
I used this regex:
On this line of text:
I put the white spaces intentionally in this long string to make it harder.
You can the regex on https://regex101.com/
Don't forget to check Python as language.
The regex-string is on the top, and you must enter it without the leading
The function
A dict can take this output.
Doing the same with
For myself, I didn't find a good solution without regex for this problem.
Often, the use of a regex can lead into the wrong direction.
I used this regex:
r"\s+?(\w+)\s+?:\s+?(\w+)"
On this line of text:
" val_1 : val_2 val_3 : val_4 val_5 : val_6 "
I put the white spaces intentionally in this long string to make it harder.
You can the regex on https://regex101.com/
Don't forget to check Python as language.
The regex-string is on the top, and you must enter it without the leading
r
and the quotes.The function
re.findall
will return all matching groups.A dict can take this output.
Doing the same with
str.split
, str.strip
etc. is a bit harder.For myself, I didn't find a good solution without regex for this problem.
Often, the use of a regex can lead into the wrong direction.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!