Explain this regex used in RoR /\A([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})\Z/i What does the \A tag do ?
+1
A:
Start of a string.
See the "Permanent Start of String and End of String Anchors" section
Chris Diver
2010-07-20 07:42:37
A:
As Chris Diver said, start of a string.
You can experiment with Regular Expressions at http://rubular.com.
Ryan Bigg
2010-07-20 07:44:29
+2
A:
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
.
paxdiablo
2010-07-20 07:46:32