Jason S
Jason S

Reputation: 189626

Matching only the beginning of a string in Python MULTILINE mode

Python's re module says this:

'^'

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

I want to use MULTILINE but I want to require a match at the beginning of the string (not just the beginning of a line). Is there a way to do this?

Upvotes: 2

Views: 672

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626738

Just use the \A anchor that matches the start of string unambiguously.

Check the Regular Expression Syntax:

\A
Matches only at the start of the string.

Upvotes: 3

Related Questions