From: Amishera Amishera on 7 Apr 2010 14:21 It is said that \A matches the beginning of the string and \Z matches the end of the string. I am not sure what means. -- Posted via http://www.ruby-forum.com/.
From: Aldric Giacomoni on 7 Apr 2010 14:22 Amishera Amishera wrote: > It is said that \A matches the beginning of the string and \Z matches > the end of the string. I am not sure what means. Oh boy. Welcome to "Regular Expressions". Time for you to use Google! Pro Tip: http://rubular.com/ will become your best friend. -- Posted via http://www.ruby-forum.com/.
From: Xavier Noria on 7 Apr 2010 14:28 On Wed, Apr 7, 2010 at 8:21 PM, Amishera Amishera <amishera2007(a)gmail.com> wrote: > It is said that \A matches the beginning of the string and \Z matches > the end of the string. I am not sure what means. Not exact, \z is the one that matches end of string. \Z still allows some optional stuff. That's regular expressions.
From: Josh Cheek on 7 Apr 2010 14:37 [Note: parts of this message were removed to make it a legal post.] On Wed, Apr 7, 2010 at 1:21 PM, Amishera Amishera <amishera2007(a)gmail.com>wrote: > It is said that \A matches the beginning of the string and \Z matches > the end of the string. I am not sure what means. > -- > Posted via http://www.ruby-forum.com/. > > "xyz\nuvw".scan(/\Ax/) # => ["x"] "uvw\nxyz".scan(/\Ax/) # => [] We are looking for the beginning of the string, followed by the character x. The string here has 2 lines, when the first line (the beginning of the string) begins with x, it matches. When the second line begins with x and the first doesn't, it does not match. ----- "uvw\nxyz".scan(/^x/)# => ["x"] "xyz\nuvw".scan(/^x/)# => ["x"] This time, we use the caret, which matches the beginning of the line, it matches in both cases ----- "uvw\nxyz".scan(/\A./) # => ["u"] "uvw\nxyz".scan(/^./)# => ["u", "x"] Now we use a dot, which will match any character. Basically telling it "find the beginning of the string followed by some character" and "find the beginning of the line followed by some character". In the first case, it matches the "u" because that is at the beginning of the string. In the second, it matches "u" and "x" because they are at the beginning of the lines.
|
Pages: 1 Prev: Dissapearing data from array Next: Is it possible, a fully general Enumerable#recursive ? |