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

Re: regexp

Expand Messages
  • crlender
    ... I m still seeing incorrect warnings for regular expressions. For example, this function String.prototype.supplant = function (o) { return
    Message 1 of 4 , Oct 27, 2008
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...>
      wrote:
      > I corrected a bug that was producing an incorrect warning on some
      > regular expression literals.

      I'm still seeing incorrect warnings for regular expressions.
      For example, this function

      String.prototype.supplant = function (o) {
      return this.replace(/{([^{}]*)}/g,
      function (a, b) {
      var r = o[b];
      return typeof r === 'string' || typeof r === 'number' ? r : a;
      }
      );
      };

      from http://javascript.crockford.com/remedial.html will generate the
      following lint messages:

      Problem at line 2 character 26: Unescaped '{'.
      return this.replace(/{([^{}]*)}/g,

      Problem at line 2 character 35: Unescaped '}'.
      return this.replace(/{([^{}]*)}/g,

      In a regex character class, parentheses don't have a special meaning
      and don't need to be escaped. In a similar vein, I've seen JSLint
      complain about character classes like [#+-], saying that the "-"
      should be escaped. Since it's at the end of the list (which is the
      recommended practice in this case), it can't be part of a range, and
      doesn't have to be escaped.

      Both tested with fulljslint.js, v 2008-10-23.


      - Conrad
    • Douglas Crockford
      ... You are correct that these things don t HAVE to be escaped. I recommend that you escape them anyway as a general approach to error avoidance.
      Message 2 of 4 , Oct 27, 2008
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "crlender" <crlender@...> wrote:

        > In a regex character class, parentheses don't have a special meaning
        > and don't need to be escaped. In a similar vein, I've seen JSLint
        > complain about character classes like [#+-], saying that the "-"
        > should be escaped. Since it's at the end of the list (which is the
        > recommended practice in this case), it can't be part of a range, and
        > doesn't have to be escaped.

        You are correct that these things don't HAVE to be escaped. I
        recommend that you escape them anyway as a general approach to error
        avoidance.
      • firstbakingbook
        Is there a simple method that jslint would be happy with for removing all matching substrings like str.replace(/#[^ n]*/g, ) (cutting all text starting with
        Message 3 of 4 , Jul 27, 2012
        • 0 Attachment
          Is there a simple method that jslint would be happy with for removing all matching substrings like

          str.replace(/#[^\n]*/g, '')

          (cutting all text starting with #, from all lines in the input)?
        Your message has been successfully submitted and would be delivered to recipients shortly.