From: Bertram Scharpf Date: 2007-07-06T17:13:57+09:00 Subject: Re: Regex: What does the ^ do? What is it called? Hi, Am Freitag, 06. Jul 2007, 14:33:12 +0900 schrieb Thomas Wieczorek: > >/^abc/ =~ "!abc" > >returns nil > >"You can use an anchor to match the beginning of a string" > > Just like the definition says ^ is used to mark the beginning of a string: > /^abc/ =~ "abc!" Another time: ^ and $ match the beginning/end of a ___line___ \A and \z match the beginning/end of a ___string___ This makes a difference when you string contains newline characters. "abc\nde\nfgh\n".scan /^./ # => ["a", "d", "f"] "abc\nde\nfgh\n" =~ /.$/ # => 2 $& # => "c" I would have guessed that /\z/ is faster than /$/ but /$/ is approximately 10 times faster here. Does anybody know why? Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de