我有一个字符串
string = "Files in this view are 168 hours away from being moved out of the active directory to the Recycle Bin."
我只想用那个地方的一些文本替换整数部分168
,我们可以找到该字符串是否包含整数
bool(re.compile('\d').search(string))
但是如何用另一个单词/字符串替换上面字符串中的整数,如" WOW Awesome
"我完全想要像
"Files in this view are WOW Awesome hours away from being moved out of the active directory to the Recycle Bin."
答案 0 :(得分:2)
使用re.sub
re.sub(r'\d+', 'Wow awesome', string)