grammar JavascriptRegexp root <- ( ( "/" regexp "/" _flags:[igm]* ) / regexp ""? ) regexp <- _match:match _alternates:( "|" match )* match <- _anchor_start:anchor_start? (!repeat) _parts:match_fragment* _anchor_end:anchor_end? match_fragment <- _content:( subexp / charset / terminal ) _repeat:repeat? anchor_start <- "^" anchor_end <- "$" repeat <- _spec:( repeat_any / repeat_required / repeat_optional / repeat_spec ) _greedy:repeat_greedy? repeat_any <- "*" repeat_required <- "+" repeat_optional <- "?" repeat_spec <- ( "{" _min:[0-9]+ "," _max:[0-9]+ "}" / "{," _max:[0-9]+ "}" / "{" _min:[0-9]+ ",}" / "{" _exact:[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 <- "\\" esc:( code:[bdDfnrsStvwW] arg:""? / code:"0" arg:[0-7]+ / code:"x" arg:( [0-9a-fA-F] [0-9a-fA-F] ) / code:"u" arg:( [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] ) ) charset_literal <- [^\\\]] / ( "\\" . ) terminal <- any_character / escape / literal any_character <- "." escape <- "\\" esc:( code:[bBdDfnrsStvwW1-9] arg:""? / code:"c" arg:. / code:"0" arg:[0-7]+ / code:"x" arg:( [0-9a-fA-F] [0-9a-fA-F] ) / code:"u" arg:( [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] ) / code:"0" arg:""? ) literal <- ( ""? literal:[^|\\/.\[\(\)?+*$^] ) / ( "\\" literal:. )