From: Ammar Ali Date: 2010-11-09T19:20:47+09:00 Subject: Re: Regexp ambiguity/error My bad, again. I missed the ':' in all of those attempts. Sorry about the noise. Regards, Ammar On Tue, Nov 9, 2010 at 11:42 AM, Ammar Ali wrote: > Hello, > > This is definitely an edge case, but an interesting one. Suppose we > have a configuration string like "mux:off mix:on" and we want to match > the "mix:on" (actually either) part passively (i.e. not captured). > > >>> "mux:on mix:off" =~ /\b(?mix:(on|off))\b/ > => 4 > > Oops, forgot about options. 100% understandable. > > > Several attempts to work around it > > Wrap one of the option characters in a set > >>> "mux:on mix:off" =~ /\b(?[m]ix:(on|off))\b/ > SyntaxError: (irb):2: undefined group option: /\b(?[m]ix:(on|off))\b/ >        from /Users/ammar/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `
' > > Wrap all option characters in individual sets > >>> "mux:on mix:off" =~ /\b(?[m][i][x]:(on|off))\b/ > SyntaxError: (irb):3: undefined group option: /\b(?[m][i][x]:(on|off))\b/ >        from /Users/ammar/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `
' > > Wrap the option characters in a group > >>> "mux:on mix:off" =~ /\b(?(mix):(on|off))\b/ > SyntaxError: (irb):4: undefined group option: /\b(?(mix):(on|off))\b/ >        from /Users/ammar/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `
' > > Move the anchors inside the passive group > >>> "mux:on mix:off" =~ /(?\b(([m]ix):(on|off))\b)/ > SyntaxError: (irb):5: undefined group option: /(?\b(([m]ix):(on|off))\b)/ >        from /Users/ammar/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `
' > > > If the passivity is dropped, it works as intended, of course. > >>> "mux:on mix:off" =~ /\b(mix:(on|off))\b/ > => 7 > > The same occurs with ruby 1.8, but with a slightly different error message: > >  undefined (?...) sequence: > > I was hoping that one of the workarounds above would work, but now I'm > thinking this is might be a bug. I want to see what others think > before I cry wolf. > > Regards, > Ammar > >