-2

In Python I want to replace <phrase>the cow jumped over the moon</phrase> with <phrase>the_cow_jumped_over_the_moon</phrase> so only within <phrase> and </phrase> blank spaces should be replaced with _ which is an underscore

All other places should not be changed

TrebledJ
  • 8,713
  • 7
  • 26
  • 48
  • Does this answer your question? [Python: Replace with regex](https://stackoverflow.com/questions/3997525/python-replace-with-regex) – keso Feb 26 '20 at 07:43

1 Answers1

0

Please use the replace method to do your task

msg1 = "the cow jumped over the moon"
print(str(msg1).replace(" ","_"))

Output:

the_cow_jumped_over_the_moon
Ratnesh
  • 1,554
  • 3
  • 12
  • 28