On Fri, 12 Dec 2003 03:31:11 +0900, Ceri Storey wrote:

> On Fri, Dec 12, 2003 at 03:17:51AM +0900, Luke A. Kanies wrote:
>> This code strips out the 'a' in 'alias'.  In other words, the anchor '^'
>> is anchoring against the beginning of a line, rather than the beginning of
>> the string.
> 
> I had that problem a day or two ago...
> 
>> How do I specifically anchor against the beginning of a string in ruby,
>> _not_ the beginning of a line in a string?
> 
> Use \A for the beginning, and \Z for the end. I believe.


Use '\z'  (lowercase) if you want to match the end.

server> irb
irb(main):001:0> /x\Z/.match("ax\n").to_a
=> ["x"]
irb(main):002:0> /x\z/.match("ax\n").to_a
=> []
irb(main):003:0> /x\z/.match("ax").to_a
=> ["x"]
irb(main):004:0>

--
Simon Strandgaard