From: "David A. Black" Date: 2008-11-29T22:13:55+09:00 Subject: [ruby-core:20165] Re: \Z? in regular expression in 1.9.1 Hi -- On Sat, 29 Nov 2008, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: [ruby-core:20162] Re: \Z? in regular expression in 1.9.1" > on Sat, 29 Nov 2008 19:42:09 +0900, "=?ISO-8859-2?Q?Rados=B3aw_Bu=B3at?=" writes: > > |> Could someone shed some light on whether it is 1.9.1 engine restriction, > |> general regular expressions > |> restriction or possible 1.9.1 bug? > |> > |> Just in case: this regexp comes from autospec in RSpec. > | > |I think this is expected behavior. "\Z" is zero width assertion so it > |doesn't make sense to mix it with "?" operator. Your regexp is the > |same as: > | /\n(\.\/)?(.*spec\.rb):[\d]+:/ > > That's right. But perhaps we should allow repeat quantifier after > anchors since Perl and old Ruby does. Does it make sense, though, for zero-width assertions? It's like saying: this either is, or isn't, the end of the string, which is always true. Or this either is, or isn't, a word boundary, etc. Also, it's not allowed unconditionally in 1.8: >> /\Z?/ SyntaxError: compile error (irb):5: invalid regular expression; there's no previous pattern, to which '?' would define cardinality at 3: /\Z?/ I think it groups the anchor with whatever comes right before it, and that's the target for the quantifier. >> /a\Z?/.match("bcde").to_a => [""] I guess that's harmless but I can't think of any use for it. David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS (Jan 12-15) | ADVANCING WITH RAILS (Jan 19-22) * Both in Fort Lauderdale, FL * Co-taught with Patrick Ewing See http://www.rubypal.com for details Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)