I need an optimised way to replace all trailing characters starting from a '/' in a string.
For example:
mytext = "this is my/string"
i want a result like this
mytext = "this is my/text"
only the string after '/' must be replaced and must be done in optimised way. can anyone find a solution for me?
I'm not sure what you mean by optimized but i'd do:
>>> import re
>>> mytext = "this is my/string"
>>> re.sub('/.*','/text',mytext)
'this is my/text'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With