From: Simon Strandgaard Date: 2004-04-30T22:35:21+09:00 Subject: Re: Why is regexp "\Amax_repeats=(\d+)" not equal to "^max_repeats=([0-9]+)" ? "Martin Elzen" wrote: > I'm trying to learn how to program in Ruby, and yesterday I came across a > Regexp issue I can't figure out. I want to parse a commandline argument of > the form: max_repeats= > > After studying the 'pick-axe' book, I came up with the line: > regexp = Regexp.new("\Amax_repeats=(\d+)") > > but the above regexp fails to match with correct input. When I changed that > line to the following: > regexp = Regexp.new("^max_repeats=([0-9]+)") > > it *does* match correctly with the proper input. > Watch out about escaping inside double quoted strings.. observe the difference irb(main):001:0> re = Regexp.new("\Ax") => /Ax/ irb(main):002:0> re.match("xxx").to_a => [] irb(main):003:0> re = Regexp.new('\Ax') => /\Ax/ irb(main):004:0> re.match("xxx").to_a => ["x"] irb(main):005:0> Does this help you ? -- Simon Strandgaard