views:

46

answers:

3

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
A: 

As Chris Diver said, start of a string.

You can experiment with Regular Expressions at http://rubular.com.

Ryan Bigg
+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