Regex can be useful for this if need to build it with more rules.
Example let say it's
I have done this before for a subtext parser i wrote,i had to add many rules that would have been very difficult to write with just string methods and loops.
Example let say it's
?
instead of .
,it should normally be new line there to. I have done this before for a subtext parser i wrote,i had to add many rules that would have been very difficult to write with just string methods and loops.
import re >>> s = 'I want to be a developer. I also want to learn AWS. I am going to practice joining strings.' >>> result = re.sub(r'\.\s', r'\n', s) >>> >>> print(result) I want to be a developer I also want to learn AWS I am going to practice joining strings.So if get a new text with a new problem,can build on regex or just pass text to a new
re.sub()
if regex get to complex in one go.>>> import re >>> >>> s = 'I want to be a developer. I also want to learn AWS. What If I Don’t Know If the Woman Is Married or Not? hello world a new line' >>> result = re.sub(r'\.\s|\?\s', r'\n', s) >>> >>> print(result) I want to be a developer I also want to learn AWS What If I Don’t Know If the Woman Is Married or Not hello world a new line