I have to remove first instances of the word "hard" from the given string but I am not sure how to do remove it both with and without spaces:
For example:
string1 = "it is a hard rock" needs to become "it is a rock"
string2 = "play hard" needs to become "play"
However, when I use
string1 = string1.replace(hard+ ' ', '', 1)
it will not work on string2 as hard comes at the end without spaces. Any way to deal with this?
Lastly if we have string3
string3 = "play hard to be hard" becomes "play to be hard"
We want only the first occurrence to be replaced.