Given the following regular expression:

/([^*#]+|#(?!#|\*)|\*(?!#))+/

I wanted to make it more readable by inserting some comments, so I
tried adding the "x" option and it no longer compiled:

/([^*#]+|#(?!#|\*)|\*(?!#))+/x

If you try it in irb you'll see a message similar to this:

SyntaxError: compile error
(irb):31: unmatched (: /([^*#]+|#(?!#|\*)|\*(?!#))+/

To get this to compile I had to add additional backslashes to escape
the '#' character in the negative lookahead subexpressions:

/([^*#]+|#(?!\#|\*)|\*(?!\#))+/x

The '#' character normally matches itself in a regular expression.
With the "x" option I expect it to have a special meaning (indicating
a comment) but in one special position (immediately after the opening
brace and question mark):

(?# comment )

Is this a bug in the regular expression engine, undocumented or am I
missing something?

No big deal, the thing is compiling, but I'd like to understand this a
bit better.

Cheers,
Greg