To match an empty string - even in multi-line mode - you can use \A\Z , therefore:
re.compile('\A\Z|\A\Z*|\A\Z+')
The difference is that \A and \Z are the beginning and end of a line, while ^ and $ they can correspond to the beginning / end of lines, so $^|$^*|$^+ can potentially correspond to a line containing newlines (if the flag is enabled).
And so as not to go anywhere (even an empty line), just try to find the content before the line starts, for example:
re.compile('.\A|.\A*|.\A+')
Since no characters can be before \ A (by definition), this will always not match.
Peter Boughton Jun 02 '09 at 17:45 2009-06-02 17:45
source share