Regex - replace space in string that has '.com Capital letter' with new line
Clash Royale CLAN TAG#URR8PPP
Construct your regex here: regex101.com - make sure to switch to pythons syntax. After finishing it use
– Patrick Artner
9 mins ago
This will take me an hour to figure out as I don't know regex and I'm already running short on sleep. @PatrickArtner Thank you, I'll look into it.
– Ricale
8 mins ago
Regex - replace space in string that has '.com Capital letter' with new line
I have a string with a space that I need to replace. The pattern is .com followed by a space and then any capital letter.
An example would be:
".com T"
The space between the .com and T needs to be replaced by a new line.
Construct your regex here: regex101.com - make sure to switch to pythons syntax. After finishing it use
re.sub
from the re
- module and code the python prog to do it.– Patrick Artner
9 mins ago
re.sub
re
This will take me an hour to figure out as I don't know regex and I'm already running short on sleep. @PatrickArtner Thank you, I'll look into it.
– Ricale
8 mins ago
1 Answer
1
You can do it with regex like this :
import re
l = ".com T"
m = re.sub("(w+)s+(w+)", r"1n2", l)
print(m)
or with join :
m = "n".join(l.split())
or with replace :
m = l.replace(" ", "n")
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Have you made any attempt to write such a regular expression yourself yet? Post what you've tried
– CertainPerformance
12 mins ago