Problem: I'm trying to replace mutiple specific sequences in a string with another mutiple specific sequences of floating point representations in Python.
I have an array of strings in a JSON-file, which I load to a python script via the json-module. The array of strings:
{
"LinesToReplace": [
"_ __ ___ ____ _____ ______ _______ ",
"_._ __._ ___._ ____._ _____._ ______._ ",
"_._ _.__ _.___ _.____ _._____ _.______ ",
"_._ __.__ ___.___ ____.____ _____._____ ",
"_. __. ___. ____. _____. ______. "
]
}
I load the JSON-file via the json-module:
with open("myFile.json") as jsonFile:
data = json.load(jsonFile)
I'm trying to replace the sequences of _
with specific substrings of floating point representations.
Specification:
- Character to find in a string must be a single
_
or a sequence of multiple_
. - The length of the sequence of
_
is unknown. - If a single
_
or a sequence of multiple_
is followed by a.
, which is again followed by a single_
or a sequence of multiple_
, the.
is part of the_
-sequence. - The
.
is used to specify decimals - If the
.
isn’t followed by a single_
or a sequence of multiple_
, the.
is not part of the_
-sequence. - The sequence of
_
and.
is to be replaced by floating point representations, i.e.,