Does this regex mean it has to start with A, end with Z?
re.search("\A[0-9A-Za-z_-]+\Z", sometext)
Does this regex mean it has to start with A, end with Z?
re.search("\A[0-9A-Za-z_-]+\Z", sometext)
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.
What is "it"?
If you're talking about a string. Yes, it does: \A means beginning of a string , \Z means end of a string.
If you are talking about a line (inside a string), you will have to insert boundary operators:
"^[0-9A-Za-z_-]+$"
^ ("caret") specifies beginning of a line; *$ ("dollar sign") specifies the end of a line.
If you are talking about a word: no, it does not; you did not specify start or end of a word.
Just remove the '\' and you will get what you want.
"^A[0-9A-Za-z_-]+Z$"