I have a text string that contains numbers. Plus, I have a number list. I want to replace the numbers inside the string with numbers from the list in the order of the string and list.
By using a Regex I extracted from the string the existing numbers and passed them to the list as well and now I have a match between the original number and the alternate number. However, it is still unclear how I can find adjustments and make replacements in order.
with this line, I extract the numbers from the given string:
list_of_numbers_in_string = [int(x) for x in re.findall('\d+', str)]
And now I wonder how it can be used, or another method to get the desired result and from this input:
data = 'readingOrder {index:24;} person {offset:0; length:7;} textStyle {offset:0; length:7; underlined:true;} place {offset:52; length:8;} textStyle {offset:52; length:8; underlined:true;}'
new_numbers = [24, 0, 12, 0, 12, 58, 14, 58, 14]
get this output:
corrected_data = 'readingOrder {index:24;} person {offset:0; length:12;} textStyle {offset:0; length:12; underlined:true;} place {offset:58; length:14;} textStyle {offset:58; length:14; underlined:true;}'