>>> import re
>>> inputStr = "hello 123 world 456"
>>> re.sub("\d+", "222", inputStr)
'hello 222 world 222'
-----------------------------------------------------------------------
>>> import re
>>> inputStr = "hello a123 world 456"
>>> re.sub("\d+", "222", inputStr)
'hello a222 world 222'
-----------------------------------------------------------------------
沒有留言:
張貼留言