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

Unexpected '\' Error regex bug

Expand Messages
  • m_blasz
    I have the following code: var id = +/ d+/.exec(rId)[0]; and get the following error: Problem at line 240 character 24: Unexpected . The code is valid so it
    Message 1 of 3 , Oct 8, 2011
    • 0 Attachment
      I have the following code:

      var id = +/\d+/.exec(rId)[0];

      and get the following error:

      Problem at line 240 character 24: Unexpected '\'.

      The code is valid so it looks like jslint doesn't pick up regex metacharacters, hence bug.
    • Merlin
      ... Just because code is valid JavaScript does not mean that it is also acceptable to JSLint. JSLint is a code quality tool which enforces stricter standards
      Message 2 of 3 , Oct 8, 2011
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "m_blasz" <blasz_2000@...> wrote:
        >
        > I have the following code:
        > var id = +/\d+/.exec(rId)[0];
        > and get the following error:
        > Problem at line 240 character 24: Unexpected '\'.
        > The code is valid so it looks like jslint doesn't pick up regex metacharacters, hence bug.

        Just because code is valid JavaScript does not mean that it is also acceptable to JSLint.

        JSLint is a code quality tool which enforces stricter standards than a JS interpreter.

        The + sign is redundant.

        var rId = "123";
        var id = /\d+/.exec(rId)[0];

        would be valid, as would

        var rId = "123";
        var id = +(/\d+/.exec(rId)[0)];
      • Merlin
        Message 3 of 3 , Oct 8, 2011
        • 0 Attachment
          > var rId = "123";
          > var id = /\d+/.exec(rId)[0];
          >
          > would be valid, as would
          >
          > var rId = "123";
          > var id = +(/\d+/.exec(rId)[0]); // corrected
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.