Sorry if the title is a little vague can't think of a better one right now.
I'm struggling to find the correct regular expression for a little test of mine:
Input and Output:
"Hello" --------------> ("Hello", "")
"How are you doing?" -> ("How", "are you doing?")
"" -------------------> ("", "")
"!h0w are you?" ------> ("!h0w", "are you?")
"#" ------------------> ("#", "")
":::::::" ------------> (":::::::", "")
The Closest regular expression so far is "(\.?)(.*?)((\s+?)(.*?)$|$)" but it gives a lot of unwanted data, like
regex = lambda text: re.search("(\.?)(.*?)((\s+?)(.*?)$|$)", text).groups()
# Input and Output
regex("Hello") --------------> ('', 'Hello', '', None, None)
regex("How are you doing?") -> ('', 'How', ' are you doing?', ' ', 'are you doing?')
regex("") -------------------> ('', '', '', None, None)
regex("!h0w are you?") ------> ('', '!h0w', ' are you?', ' ', 'are you?')
regex("#") ------------------> ('', '#', '', None, None)
regex(":::::::") ------------> ('', ':::::::', '', None, None)
None what I would prefer is:
x, y = re.search(pattern, string).groups()
If that is not possible, can someone improve upon the existing regular expression? I've been trying to improve it for a bit but I can't seem to make it any better.
Cannot use str.split for this, trying to figure out how to do things with regular expressions.