开发者

Regular Expressions: What does the \A tag do?

开发者 https://www.devze.com 2023-01-08 13:25 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号