I have a very large string consiting of a series of numbers separated by one or more spaces. Some of the numbers are equal to -123, and the rest can be any random number.
example_string = "102.3 42.89 98 812.7 374 5 -123 8 -123 13 -123 21..."
I would like to replace the values that are not equal to -123 with 456 in the most efficient way possible.
updated_example_string = "456 456 456 456 456 456 -123 456 -123 456 -123 456..."
I know that python's regular expression library has a sub method that will replace matching values quite efficiently. Is there a way to replace values that DO NOT match? As I mentioned, this is a rather large string, coming from a source file around 100MB. Assuming there's a way to use re.sub to accomplish this task, is that even the correct/most efficient way of handling such problem?