grammar JavascriptRegexp root <- ( ( "/" regexp "/" fl:[igm]* ) / regexp ) regexp <- match ( "|" regexp )? match <- anchor_start? ( ( subexp / charset / terminal ) repeat? )* anchor_end? anchor_start <- "^" anchor_end <- "$" repeat <- ( repeat_any / repeat_required / repeat_optional / repeat_spec ) repeat_greedy? repeat_any <- "*" repeat_required <- "+" repeat_optional <- "?" repeat_spec <- "{" [0-9]+ "," [0-9]+ "}" / "{," [0-9]+ "}" / "{" [0-9]+ ",}" / "{" [0-9]+ "}" repeat_greedy <- "?" subexp <- "(" ( subexp_no_capture / subexp_positive_lookahead / subexp_negative_lookahead )? regexp ")" subexp_no_capture <- "?:" subexp_positive_lookahead <- "?=" subexp_negative_lookahead <- "?!" charset <- "[" "^"? ( charset_range / charset_terminal )* "]" charset_range <- charset_terminal "-" charset_terminal charset_terminal <- charset_escape / charset_literal charset_escape <- ( backspace_esc / control_esc / digit_esc / non_digit_esc / form_feed_esc / line_feed_esc / carriage_return_esc / white_space_esc / non_white_space_esc / tab_esc / vertical_tab_esc / word_esc / non_word_esc / octal_esc / hex_esc / unicode_esc / null_esc / literal_esc ) charset_literal <- [^\\\]] terminal <- any_character / escape / literal any_character <- "." escape <- ( word_boundary_esc / non_word_boundary_esc / control_esc / digit_esc / non_digit_esc / form_feed_esc / line_feed_esc / carriage_return_esc / white_space_esc / non_white_space_esc / tab_esc / vertical_tab_esc / word_esc / non_word_esc / back_reference / octal_esc / hex_esc / unicode_esc / null_esc / literal_esc ) literal <- [^|\\/.\[\(\)?+*$^] back_reference <- "\\" [1-9] word_boundary_esc <- "\\b" non_word_boundary_esc <- "\\B" backspace_esc <- "\\b" control_esc <- "\\b" . digit_esc <- "\\d" non_digit_esc <- "\\D" form_feed_esc <- "\\f" line_feed_esc <- "\\n" carriage_return_esc <- "\\r" white_space_esc <- "\\s" non_white_space_esc <- "\\S" tab_esc <- "\\t" vertical_tab_esc <- "\\v" word_esc <- "\\w" non_word_esc <- "\\W" octal_esc <- "\\0" [0-7]+ hex_esc <- "\\x" [0-9a-fA-F] [0-9a-fA-F] unicode_esc <- "\\u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] null_esc <- "\\0" literal_esc <- "\\" .