Tutorial :Regular Expressions


Explain this regex used in RoR /\A([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})\Z/i What does the \A tag do ?


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.


Start of a string.

See the "Permanent Start of String and End of String Anchors" section


As Chris Diver said, start of a string.

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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »