Suppose I have a string
the_string = "the brown fox"
And I wan't to replace the spaces with a number of characters, for example, 5 dash marks
new_string = "the-----brown-----fox"
but this will be a variable, so i cant just do:
the_string = 'the brown fox'
new_string = re.sub(r'\s', '-----', the_string)
I need something like the following:
the_string = 'the brown fox'
num_dashes = 5
new_string = re.sub(r'\s', r'-{num_dashes}', the_string)
Is something like this possible?
new_string = the_string.replace(' ', '-' * num_dashes).remodule for a variable number of whitespace characters. Thestr.replacemethod does not work with regular expressions.