Reputation: 20637
I am trying to manipulate a string using Jython, I have included below an example string:
This would be a title for a website :: SiteName
This would be a title for a website :: SiteName :: SiteName
How to remove all instances of ":: Sitename" or ":: SiteName :: SiteName"?
Upvotes: 0
Views: 2436
Reputation: 414675
For such simple example it is unnecessary but in general you could use re
module.
import re
sitename = "sitename" #NOTE: case-insensitive
for s in ("This would be a title for a website :: SiteName :: SiteName",
"This would be a title for a website :: SiteName"):
print(re.sub(r"(?i)\s*::\s*%s\s*" % sitename, "", s))
Upvotes: 0
Reputation: 86442
No different from regular Python:
>>> str="This would be a title for a website :: SiteName"
>>> str.replace(":: SiteName","")
'This would be a title for a website '
>>> str="This would be a title for a website :: SiteName :: SiteName"
>>> str.replace(":: SiteName","")
'This would be a title for a website '
Upvotes: 2