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

JSON regular expression fails to recognize JSON in Netscape <= 7.1

Expand Messages
  • Peter Michaux
    Hi, I just did some tests in some version of Netscape Navigator. The following fails in version
    Message 1 of 2 , Jan 11, 2007
    • 0 Attachment
      Hi,

      I just did some tests in some version of Netscape Navigator. The
      following fails in version <= 7.1 because the regular expression can't
      match the double quotes around the letter 'a' in the json string being
      compared to the regular expression. Both NN7.2 and Firefox 1.0 both
      return true for this test.

      /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test('{"a":3}')

      NN6 is capable of all the other JavaScript I am using (Ajax, Dom
      manipulation, Events) and it seems ashame this regular expression is
      the single part of the JSON library that requires such a new browser.
      Would there be a way to write this regular expression so it works as
      far back as NN6 or at least farther back than NN7.2? If not what is it
      in the regular expression that is failing to recognize this simple
      JSON string?

      Thank you,
      Peter
    • Douglas Crockford
      ... n r t])+?$/.test( { a :3} ) ... I don t know what was wrong with NN6. If I were to guess, it would be that it did not support the lazy quantifiers, *? and
      Message 2 of 2 , Jan 11, 2007
      • 0 Attachment
        --- In json@yahoogroups.com, "Peter Michaux" <petermichaux@...> wrote:
        >
        > Hi,
        >
        > I just did some tests in some version of Netscape Navigator. The
        > following fails in version <= 7.1 because the regular expression can't
        > match the double quotes around the letter 'a' in the json string being
        > compared to the regular expression. Both NN7.2 and Firefox 1.0 both
        > return true for this test.
        >
        > /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u
        \n\r\t])+?$/.test('{"a":3}')
        >
        > NN6 is capable of all the other JavaScript I am using (Ajax, Dom
        > manipulation, Events) and it seems ashame this regular expression is
        > the single part of the JSON library that requires such a new browser.
        > Would there be a way to write this regular expression so it works as
        > far back as NN6 or at least farther back than NN7.2? If not what is it
        > in the regular expression that is failing to recognize this simple
        > JSON string?

        I don't know what was wrong with NN6. If I were to guess, it would be
        that it did not support the lazy quantifiers, *? and +?. If you
        replaced them with the greedy quantifiers, * and +, it might work.

        But there is a bug in IE6 in which the greedy quantifiers cause the
        regexp to run in exponential time. When the text gets big, IE gets
        really really slow.
      Your message has been successfully submitted and would be delivered to recipients shortly.