Reputation: 56
Explain this regex used in RoR /\A([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})\Z/i What does the \A tag do ?
Upvotes: 1
Views: 156
Reputation: 881323
The \A
and \Z
markers are meant to provide a way to identify the start and end of a string, primarily for multi-line strings.
If you're processing one line at a time (which is mostly, but not completely, the case with UNIXy text processing tools), you could simply use ^
and $
because start/end of string is the same as start/end of line.
For example, the single string:
This is line 1
and this is line 2
would have two matches for ^
, one before This
and one between 1
and and
. It would only have one match for \A
, before This
.
Upvotes: 2
Reputation: 107718
As Chris Diver said, start of a string.
You can experiment with Regular Expressions at http://rubular.com.
Upvotes: 0
Reputation: 19812
Start of a string.
See the "Permanent Start of String and End of String Anchors" section
Upvotes: 1