0

I have a string

string = "Files in this view are 168 hours away from being moved out of the active directory to the Recycle Bin."

I just want to replace the integer part 168 with some text at that place, we can find whether the string contains an integer or not like

bool(re.compile('\d').search(string))

But how to replace the integers in the above string with a another word/string like "WOW Awesome" and totally i want the result like

"Files in this view are WOW Awesome hours away from being moved out of the active directory to the Recycle Bin."
1
  • Use re.sub to replace using a regex search. Commented Sep 29, 2015 at 17:36

1 Answer 1

2

Use re.sub

re.sub(r'\d+', 'Wow awesome', string)
Sign up to request clarification or add additional context in comments.

1 Comment

aahhh thats very simple Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.