Alex Gao Alex Gao - 11 months ago 74
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?

Answer Source

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

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

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