Why does re.compile(r"^[\s]+|[\s]+$")
matches trailing and leading whitespaces in a string " Hello "
, but re.compile(r"^[\s]+[\s]+$")
does not? The latter (without |) seems perfectly fine to me:
^[\s]+
- should match at least one trailing whitespace at the beginning of the searched string[\s]+$
- should match at least one leading whitespace at the end of the searched string
But why doesn't it work? I don't understand how the bitwise OR (|) operator makes the difference.