Subject: | Regexp::Debugger always treats "#" as a comment character regardless of the /x flag. |
Regexp::Debugger is awesome! But I did find a bug in it relating to the /x flag...
Here is a very simple test case:
perl -MRegexp::Debugger -e '/(#)/'
This is a perfectly valid regular expression which should match (and capture) a literal "#" character, but if Regexp::Debugger is loaded, it treats the "#" as a comment character, incorrectly commenting out the closing parenthesis and causing an error:
Unmatched ( in regex; marked by <-- HERE in m/(?#R_d:0)(?>\A(?{Regexp::Debugger::_reset_debugger_state()})(?!)|\G(?{Regexp::Debugger::_reset_debugger_state_rematch()})(?!))|( <-- HERE ?:(?{Regexp::Debugger::_report_event(0, 0, pos()); $^R})(?=[\d\D]?(?{1}))(?:((?{Regexp::Debugger::_report_event(0, 1, pos()); $^R})(?=[\d\D]?(?{1}))(?:(?>(?{local $Regexp::Debugger::prevpos=pos})#)(?{
if (defined $Regexp::Debugger::prevpos && $Regexp::Debugger::prevpos < pos){
Regexp::Debugger::_report_event(0, 2, $Regexp::Debugger::prevpos);
Regexp::Debugger::_report_event(0, 2+1, pos());
}$^R })|(?{
Regexp::Debugger::_report_event(0, 2, pos());
$^R
})(?!)))(?{Regexp::Debugger::_report_event(0, 4, pos()); $^R})(?=[\d\D]?(?{1}))|(?{Regexp::Debugger::_report_event(0, 5, pos()); $^R})(?=[\d\D]?(?{1}))(?!))/ at (eval 8) line 8.
(This regular expression can also be entered into "rxrx" with similar results.)
The "#" should behave as a comment character like this IF the /x flag is on, but in this case it isn't, so it should match literally. (Using "\#" is a workaround for this bug.)
This bug is present in every version of Regexp::Debugger from 0.001000 through 0.002004, which is the current version.