rsplit() starts splitting at the end of the line. How to start splitting at the end of a line when using re.split() ?
Example:
import re splitme = "a!b?c!d" re.split(r"[!\?]", splitme, maxsplit = 1)
Return:
a
But I want:
d
While I was writing this question, I realized that I can use
re.split(r"[!\?]", splitme)[-1]
But this does not seem to be the most efficient way, since it splits the entire line, and we can stop after the first match (on the right).
source share