A Regexp::Parser Subclass for JavaScript Regular Expressions


  use Regexp::Parser::JavaScript;
  my $parser = Regexp::Parser::JavaScript->new;
  my @error;
  ## Prepare a callback function invoked whenever an error or warning
  ## is raised by the parser.
  $parser->onerror (sub {
    my %args = @_;
    my $error_message = '';
    if ($args{level} eq 'w') {
      $error_message .= 'Warning: ';
    } else {
      $error_message .= 'Error: ';
    $error_message .= sprintf $args{type}, @{$args{args}};
    $error_message .= ' (';
    $error_message .= substr ${$args{valueref}},
        $args{pos_start}, $args{pos_end} - $args{pos_start};
    $error_message .= ')';
    $error_message .= "\n";
    push @error, $error_message;
  ## Parse the regular expression given as a string.
  ## Use |eval| to catch an exception that would be thrown if the
  ## regular expression contains a fatal error.
  eval {
    $parser->parse ($regexp_as_string);
  if ($parser->errnum) {
    ## @error contains at least one fatal error.
    warn @error;
  } else {
    ## @error contains no fatal error.
    warn @error;
    ## Now, $parser->root contains the root node of the parsed regular
    ## expression tree.  See |perldoc Regexp::Parser| for more information.


The Regexp::Parser::JavaScript modules provides a subclass of the Regexp::Parser, a regular expression parser module. The Regexp::Parser::JavaScript module provides an implementation of the parser for the regular expression language as defined by ECMA 376 Third Edition (the ECMAScript specification), modified for compatibility with Web browser implementations.

Apart from this additional function, this module provides the same interface as the one applied by the Regexp::Parser::Perl58 module. For more information, see Regexp::Parser::Perl58.


The Regexp::Parser::JavaScript module provides same methods as Regexp::Parser::JavaScript. See Regexp::Parser::Perl58.


The Regexp::Parser::JavaScript module reports same kinds of errors as the Regexp::Parser module does to the callback function specified by the onerror method, if any. In addition, it might also have an additional error type: RPJSe_OCTESC.


This error is reported when an octal escape sequence is used in the regular expression. The octal escape sequence is not part of the ECMAScript specification though it is supported by Web browsers for backward compatibility.


This module requires Perl 5.10.0 or later.

This module depends on Regexp::Parser and Regexp::Parser::Perl58 modules.


The latest version of this module is available at

Regular expression visualizer It uses this module to parse Perl 5.8 regular expressions.

Regexp::Parser - A superclass, available from CPAN.

Regexp::Parser::Perl58 - A superclass.


CVS log:,cvslog.

Bug tracking system:


Wakaba <>.


Copyright 2008-2009 Wakaba <>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.