Incorrect RegExp detection in JavaScript

Issue #403 resolved
Former user created an issue

In !JavaScript, a single forward slash following one of {{{ [({=,:;!%^&*|?~+- }}} starts a regular expression. Spaces are not required. For example, this is valid syntax: {{{ if (!/regexp/.test(foo)) }}} but this is not recognized by Pygments.

See more examples at

Reported by Pumbaa80

Comments (7)

  1. Anonymous

    I had a look at [] and I'm afraid there are [ some more issues] with !JavascriptLexer.

    First, according to [ the JavaScript spec], this should be the right way to match operators and punctuators:

    (r'=|++|--|~|&&|\\?|:|\\|\\||\\\\|(<<|>>>?|==?|!=?|[<>+-*%&\\|\\^/])=?', Operator)
    (r'[{}()\\[\\].;,]', Punctuation)

    Second, character classes need a special treatment... (use several states?)

    Once this is fixed, the detection of a regexp literal's end (cf. lines 47 to 49 in can be simplified/fixed. This should sufficiently replace the three lines:

    ...   /([gim]+\\b|\\B)', String.Regex)

    !ActionScriptLexer and !ActionScript3Lexer might need a fix, too (?).

  2. Log in to comment