Alex Gao Alex Gao - 10 months ago 71
Python Question

If there difference between `\A` vs `^` (caret) in regular expression?


module documentation says:

: (Caret.) Matches the start of the string, and in MULTILINE mode also matches immediately after each newline.

: Matches only at the start of the string.

Is there any difference when using them?


Both of these match:'^abc', 'abc')'\Aabc', 'abc')

This also matches:'^abc', 'firstline\nabc', re.M)

This does not:'\Aabc', 'firstline\nabc', re.M)