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

RegExp error: Unexpected '.'.

Expand Messages
  • pauanyu
    var regexp = / s+(?!.*[ =])/gm; I am a bit confused as to why JSLint doesn t like this. It doesn t seem to cause problems or throw exceptions in the browsers
    Message 1 of 11 , May 27, 2009
      var regexp = /\s+(?!.*[\=])/gm;

      I am a bit confused as to why JSLint doesn't like this. It doesn't seem to cause problems or throw exceptions in the browsers I've used, so what's the rationale here?
    • Douglas Crockford
      ... RegExp is often used for security-related input validation. There have been cases where bad stuff has gotten through the filters because . matches too
      Message 2 of 11 , May 27, 2009
        --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
        >
        > var regexp = /\s+(?!.*[\=])/gm;
        >
        > I am a bit confused as to why JSLint doesn't like this. It doesn't seem to cause problems or throw exceptions in the browsers I've used, so what's the rationale here?


        RegExp is often used for security-related input validation. There have been cases where bad stuff has gotten through the filters because . matches too much. If that isn't important to you, turn off the regexp option.
      • christian.wirkus
        Try this: var regexp = / s+(?! .*[ =])/gm; JSLint wants the . to be escaped. Regular expressions are objects and have methods, like: var boolean =
        Message 3 of 11 , May 27, 2009
          Try this:
          var regexp = /\s+(?!\.*[\=])/gm;

          JSLint wants the . to be escaped. Regular expressions are objects and have methods, like:
          var boolean = /\s/.test("Hi there");

          So what's the problem? You could write this:
          var regexp = /\/.test("Hi there");/;

          This looks like testing if there is a \ in the string (except for \ should be escaped and there is this /; at the end), but of course, is not. Regular expressions are puzzling - and JSLint wants you to be aware of that:

          var regexp = /\/\.test("Hi there");/;

          Christian



          --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
          >
          > var regexp = /\s+(?!.*[\=])/gm;
          >
          > I am a bit confused as to why JSLint doesn't like this. It doesn't seem to cause problems or throw exceptions in the browsers I've used, so what's the rationale here?
          >
        • pauanyu
          ... No, I do actually want the . because the . character matches any character except newline. Thanks for trying to help, but that s not the problem. JSLint
          Message 4 of 11 , May 27, 2009
            --- In jslint_com@yahoogroups.com, "christian.wirkus" <christian.wirkus@...> wrote:
            >
            > Try this:
            > var regexp = /\s+(?!\.*[\=])/gm;
            >
            > Christian
            >

            No, I do actually want the . because the . character matches any character except newline. Thanks for trying to help, but that's not the problem.

            JSLint gives a different error message for unescaped characters:

            Unescaped 'foo'.
          • pauanyu
            ... Ah, I see, thanks for explaining. Of course, if I wanted to bypass this, I could just do [ s S], which would actually match even more than the . character.
            Message 5 of 11 , May 27, 2009
              --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
              >
              > RegExp is often used for security-related input validation. There have been cases where bad stuff has gotten through the filters because . matches too much. If that isn't important to you, turn off the regexp option.
              >

              Ah, I see, thanks for explaining. Of course, if I wanted to bypass this, I could just do [\s\S], which would actually match even more than the . character.
            • pauanyu
              ... Oh! That option. Amazing, after all this time using JSLint, I never noticed the Disallow . in RegExp literals option. Sorry for wasting your time.
              Message 6 of 11 , May 27, 2009
                --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
                >
                > If that isn't important to you, turn off the regexp option.
                >

                Oh! That option. Amazing, after all this time using JSLint, I never noticed the "Disallow . in RegExp literals" option. Sorry for wasting your time.
              • Douglas Crockford
                ... I make no claim that JSLint can prevent you from intentionally doing stupid things. It can help you make your code better, if that is of value to you.
                Message 7 of 11 , May 27, 2009
                  --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
                  >
                  > --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@> wrote:
                  > >
                  > > RegExp is often used for security-related input validation. There have been cases where bad stuff has gotten through the filters because . matches too much. If that isn't important to you, turn off the regexp option.
                  > >
                  >
                  > Ah, I see, thanks for explaining. Of course, if I wanted to bypass this, I could just do [\s\S], which would actually match even more than the . character.


                  I make no claim that JSLint can prevent you from intentionally
                  doing stupid things. It can help you make your code better, if
                  that is of value to you.
                • christian.wirkus
                  the escaped . matches anything, i think try it out
                  Message 8 of 11 , May 29, 2009
                    the escaped . matches anything, i think
                    try it out

                    --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
                    >
                    > --- In jslint_com@yahoogroups.com, "christian.wirkus" <christian.wirkus@> wrote:
                    > >
                    > > Try this:
                    > > var regexp = /\s+(?!\.*[\=])/gm;
                    > >
                    > > Christian
                    > >
                    >
                    > No, I do actually want the . because the . character matches any character except newline. Thanks for trying to help, but that's not the problem.
                    >
                    > JSLint gives a different error message for unescaped characters:
                    >
                    > Unescaped 'foo'.
                    >
                  • pauanyu
                    ... Sorry, but no. The escaped . matches only the period. Here s some proof: alert(/ ./.exec( a. )); alert(/./.exec( a. ));
                    Message 9 of 11 , May 29, 2009
                      --- In jslint_com@yahoogroups.com, "christian.wirkus" <christian.wirkus@...> wrote:
                      >
                      > the escaped . matches anything, i think
                      > try it out
                      >

                      Sorry, but no. The escaped . matches only the period.

                      Here's some proof:

                      alert(/\./.exec("a."));
                      alert(/./.exec("a."));
                    • christian.wirkus
                      Hm, you re right. The regexps tricked once more. Thanks.
                      Message 10 of 11 , May 30, 2009
                        Hm, you're right. The regexps tricked once more. Thanks.

                        --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
                        > Sorry, but no. The escaped . matches only the period.
                        >
                      • Michael Lorton
                        Some people, when confronted with a problem, think I know, I’ll use regular expressions. Now they have two problems. — Jamie Zawinski That quote is a
                        Message 11 of 11 , May 30, 2009
                          "Some people, when confronted with a problem, think 'I know, I’ll use regular expressions.' Now they have two problems."
                          — Jamie Zawinski


                          That quote is a little unfair, but not entirely inaccurate. Christian's problem may have been that the regexp generated by

                          new RegExp('\.')
                          will match any character, but the one generated by

                          /\./
                          will only match the period.

                          M.




                          ________________________________
                          From: christian.wirkus <christian.wirkus@...>
                          To: jslint_com@yahoogroups.com
                          Sent: Saturday, May 30, 2009 9:28:38 AM
                          Subject: [jslint] Re: RegExp error: Unexpected '.'.

                          Hm, you're right. The regexps tricked once more. Thanks.

                          --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
                          > Sorry, but no. The escaped . matches only the period.
                          >




                          ------------------------------------

                          Yahoo! Groups Links



                          [Non-text portions of this message have been removed]
                        Your message has been successfully submitted and would be delivered to recipients shortly.