Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does this regex mean it has to start with A, end with Z? re.search "\A[0-9A-Za-z_-]+\Z"

Tags:

python

regex

Does this regex mean it has to start with A, end with Z?

re.search("\A[0-9A-Za-z_-]+\Z", sometext)
like image 895
Blankman Avatar asked Feb 26 '23 10:02

Blankman


1 Answers

No, those are anchors.

\A means start of string, and \Z means end of string. Similarly ^ means start of line and $ means end of line.

See the documentation for the re module.

\A - Matches only at the start of the string.
\Z - Matches only at the end of the string.

like image 184
Mark Byers Avatar answered Apr 06 '23 11:04

Mark Byers