Regexp ambiguity/error

A

Ammar Ali

Hello,

This is definitely an edge case, but an interesting one. Suppose we
have a configuration string like "mux:eek:ff mix:eek:n" and we want to match
the "mix:eek:n" (actually either) part passively (i.e. not captured).

=> 4

Oops, forgot about options. 100% understandable.


Several attempts to work around it

Wrap one of the option characters in a set
"mux:eek:n mix:eek:ff" =~ /\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 `<main>'

Wrap all option characters in individual sets
"mux:eek:n mix:eek:ff" =~ /\b(?[m][x]:(on|off))\b/

SyntaxError: (irb):3: undefined group option: /\b(?[m][x]:(on|off))\b/
from /Users/ammar/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `<main>'

Wrap the option characters in a group
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 `<main>'

Move the anchors inside the passive group
"mux:eek:n mix:eek:ff" =~ /(?\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 `<main>'


If the passivity is dropped, it works as intended, of course.
=> 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
 
A

Ammar Ali

My bad, again. I missed the ':' in all of those attempts.

Sorry about the noise.

Regards,
Ammar


Hello,

This is definitely an edge case, but an interesting one. Suppose we
have a configuration string like "mux:eek:ff mix:eek:n" and we want to match
the "mix:eek:n" (actually either) part passively (i.e. not captured).

=3D> 4

Oops, forgot about options. 100% understandable.


Several attempts to work around it

Wrap one of the option characters in a set
"mux:eek:n mix:eek:ff" =3D~ /\b(?[m]ix:(on|off))\b/
SyntaxError: (irb):2: undefined group option: /\b(?[m]ix:(on|off))\b/
=C2=A0 =C2=A0 =C2=A0 =C2=A0from /Users/ammar/.rvm/rubies/ruby-1.9.2-p0/bi=
n/irb:17:in ` said:
Wrap all option characters in individual sets
"mux:eek:n mix:eek:ff" =3D~ /\b(?[m][x]:(on|off))\b/

SyntaxError: (irb):3: undefined group option: /\b(?[m][x]:(on|off))\b/
=C2=A0 =C2=A0 =C2=A0 =C2=A0from /Users/ammar/.rvm/rubies/ruby-1.9.2-p0/bi=

n/irb:17:in ` said:
Wrap the option characters in a group

SyntaxError: (irb):4: undefined group option: /\b(?(mix):(on|off))\b/
=C2=A0 =C2=A0 =C2=A0 =C2=A0from /Users/ammar/.rvm/rubies/ruby-1.9.2-p0/bi=
n/irb:17:in ` said:
Move the anchors inside the passive group
"mux:eek:n mix:eek:ff" =3D~ /(?\b(([m]ix):(on|off))\b)/
SyntaxError: (irb):5: undefined group option: /(?\b(([m]ix):(on|off))\b)/
=C2=A0 =C2=A0 =C2=A0 =C2=A0from /Users/ammar/.rvm/rubies/ruby-1.9.2-p0/bi=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,096
Latest member
ThurmanCre

Latest Threads

Top