Loading ...
Sorry, an error occurred while loading the content.

Invalid regular expression passes in JSLint.

Expand Messages
  • pauanyu
    var regexp = /foo|*/; The above is valid code in JSLint, but fails with the following error: Uncaught SyntaxError: Invalid regular expression: /foo|*/: Nothing
    Message 1 of 2 , Aug 15, 2009
    • 0 Attachment
      var regexp = /foo|*/;

      The above is valid code in JSLint, but fails with the following error:

      Uncaught SyntaxError: Invalid regular expression: /foo|*/: Nothing to repeat


      The answer, of course, is to escape the '*':

      var regexp = /foo|\*/;
    • Douglas Crockford
      ... Thanks. Please try it now.
      Message 2 of 2 , Aug 15, 2009
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
        >
        > var regexp = /foo|*/;
        >
        > The above is valid code in JSLint, but fails with the following error:
        >
        > Uncaught SyntaxError: Invalid regular expression: /foo|*/: Nothing to repeat


        Thanks. Please try it now.
      Your message has been successfully submitted and would be delivered to recipients shortly.