Java Script problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tuy Solang

    Java Script problems


    I download four scripts that are used to display
    Khmer PGN for Khmer Chess. It works fine with Netscape 7.1
    on MS Millenium, but it gave me an error(Java Script console)
    with Netscape 8.1 on MS XP. Here is the line :

    var pat_piece=/(\w{2}+)-(\w{2,3})/;

    I am familiar with C, but I have no clue with the above expression.

    Can someone help me to explain this expression?
  • Anthony Levensalor

    #2
    Re: Java Script problems

    On 1/15/2008 3:35 PM, Tuy Solang wrote:
    I download four scripts that are used to display
    Khmer PGN for Khmer Chess. It works fine with Netscape 7.1
    on MS Millenium, but it gave me an error(Java Script console)
    with Netscape 8.1 on MS XP. Here is the line :
    >
    var pat_piece=/(\w{2}+)-(\w{2,3})/;
    >
    I am familiar with C, but I have no clue with the above expression.
    >
    Can someone help me to explain this expression?
    It's a regular expression that means

    2 letters must occur one or more times and creates a backreference to them.

    Then, there must be a dash, followed by 2 or 3 more letters, and creates
    a backreference to those as well.

    It sets that pattern to the variable pat_piece, presumably to do a match
    or replace later on.

    / - starts regular expression
    ( - starts grouping for backreference
    \w - matches alpha character
    {2} - Requires exactly 2 alpha characters
    ) - closes backreference group
    - - Just a dash
    \w{2,3} - says there must be at least two letters, but three is ok too
    / - ends the regular expression
    ; - unnecessary cluttering of the end of the line, IMHO

    Hope this helps,
    ~A!



    --
    anthony at my pet programmer dot com
    CLJ FAQ:
    <URL: http://www.jibbering.com/faq/ >

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: Java Script problems

      Tuy Solang wrote:
      I download four scripts that are used to display
      Khmer PGN for Khmer Chess. It works fine with Netscape 7.1
      on MS Millenium, but it gave me an error(Java Script console)
      with Netscape 8.1 on MS XP. Here is the line :
      >
      var pat_piece=/(\w{2}+)-(\w{2,3})/;
      >
      I am familiar with C, but I have no clue with the above expression.
      >
      Can someone help me to explain this expression?
      It is an erroneous Regular Expression literal, and I would be surprised if
      there was no error in Netscape 7.1. `\w' specifies a word character, and
      the following `{2}' means two of them. Then follows a `+' which means the
      preceding expression must occur one or more times. However, the `{2}'
      quantifier must not be followed by the `+' quantifier. For a minimum number
      of characters you have to use the {n,} quantifier, with n being 2 here.

      However, it is also possible that you were looking for `(\w{2})+' instead,
      which would mean one or more occurrences of two consecutive word characters,
      or that the `+' was meant literally (designating a check move) in which case
      it should have been `\w{2}\+'. It is not clear what exactly is meant here
      because AFAICS the matched string would not be a valid token as defined in
      the PGN Specification.

      The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.




      PointedEars

      Comment

      • SAM

        #4
        Re: Java Script problems

        Tuy Solang a écrit :
        I download four scripts that are used to display
        Khmer PGN for Khmer Chess. It works fine with Netscape 7.1
        on MS Millenium, but it gave me an error(Java Script console)
        with Netscape 8.1 on MS XP. Here is the line :
        >
        var pat_piece=/(\w{2}+)-(\w{2,3})/;
        >
        I am familiar with C, but I have no clue with the above expression.
        <http://www.evolt.org/article/Regular_Express ions_in_JavaScr ipt/17/36435/>
        Can someone help me to explain this expression?
        I think that is to search a group of
        2 alphanumeric characters eventually several times
        followed by '-'
        followed by 2 or 3 alphanumeric characters

        Any string with at least 5 characters
        and among which 2 or 3 last ones are separated from the others by one -
        and these others always by number pair

        ab-p2
        ab1o-p12
        zstr45-hh
        zstr45-hhn

        --
        sm

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Java Script problems

          Thomas 'PointedEars' Lahn wrote:
          Tuy Solang wrote:
          > I download four scripts that are used to display
          >Khmer PGN for Khmer Chess. It works fine with Netscape 7.1
          >on MS Millenium, but it gave me an error(Java Script console)
          >with Netscape 8.1 on MS XP. Here is the line :
          >>
          > var pat_piece=/(\w{2}+)-(\w{2,3})/;
          >>
          >I am familiar with C, but I have no clue with the above expression.
          >>
          >Can someone help me to explain this expression?
          >
          It is an erroneous Regular Expression literal, and I would be surprised if
          there was no error in Netscape 7.1. [...]
          I installed, saw, and was surprised. The script engine of Netscape 7.1
          [NS71] accepts the above literal, indeed, and interprets it as if `\w{2}+'
          was `\w{2,}'. That bug is apparently fixed since Netscape 7.2 [NS71].

          BTW, since support for the Netscape suite and browser will cease on
          2008-02-01 [ANN] , it might be a good idea to get the Netscape installers
          while you still can; I downloaded Communicator 4.78, Navigator 6.23, 7.1,
          7.2, 8.1 and 9.0.0.5 today.

          [NS71] Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4)
          Gecko/20030624 Netscape/7.1 (ax)

          [NS72] Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2)
          Gecko/20040804 Netscape/7.2 (ax)

          [ANN]



          PointedEars
          --
          var bugRiddenCrashP ronePieceOfJunk = (
          navigator.userA gent.indexOf('M SIE 5') != -1
          && navigator.userA gent.indexOf('M ac') != -1
          ) // Plone, register_functi on.js:16

          Comment

          • SAM

            #6
            Re: Java Script problems

            Thomas 'PointedEars' Lahn a écrit :
            Thomas 'PointedEars' Lahn wrote:
            >Tuy Solang wrote:
            >>gave me an error(Java Script console)
            >>with Netscape 8.1 on MS XP. Here is the line :
            >>>
            >> var pat_piece=/(\w{2}+)-(\w{2,3})/;
            >>>
            >>Can someone help me to explain this expression?
            >It is an erroneous Regular Expression literal, and I would be surprised if
            >there was no error in Netscape 7.1. [...]
            >
            I installed, saw, and was surprised. The script engine of Netscape 7.1
            [NS71] accepts the above literal, indeed, and interprets it as if `\w{2}+'
            was `\w{2,}'. That bug is apparently fixed since Netscape 7.2 [NS71].
            Question :
            how to do to get a word with a number pair of characters ?

            (because I thought that '\w{2}+' was to do it)
            I downloaded Communicator 4.78, Navigator 6.23, 7.1,
            7.2, 8.1 and 9.0.0.5 today.
            where ? thank you

            --
            sm

            Comment

            • Gregor Kofler

              #7
              Re: Java Script problems

              SAM meinte:
              Question :
              how to do to get a word with a number pair of characters ?
              >
              (because I thought that '\w{2}+' was to do it)
              /(\w{2})+/
              Though I'm sure what you mean by "number pair of characters"...

              Perhaps you want to have a look at
              This tutorial teaches you how to create your own regular expressions, starting with the most basic regex concepts and ending with the most advanced and specialized capabilities.


              BTW:
              According to my Eclipse RegEx plugin /\w{2}+/ is accepted by JDK regular
              expressions, but not by any of the other engines offered.

              Gregor



              --
              http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
              http://web.gregorkofler.com ::: meine JS-Spielwiese
              http://www.image2d.com ::: Bildagentur für den alpinen Raum

              Comment

              • Tuy Solang

                #8
                Re: Java Script problems

                Many thank, Spock.
                After I remove the + sign out, it is working.
                About the KPGN, we modify the original one a little bit to accomodate
                2 or 3 or 4 players. So the board will have either 8x8 or 14x14.
                Here is a small sample of KPGN.

                1. SB-i1-h2 -Time 00:00:03-00:00:03
                2. WB-a6-b7 -Time 00:00:06-00:00:06
                3. NK-h14-g14 -Time 00:00:11-00:00:11-Count 1-64
                etc...
                The game is written in C using TCP/IP. Since there is limited TCP/IP
                connection, we decide to write the Java Script and automatically
                download to any user homepage. This will allow more
                people to watch the game. Both C and Java will be free.

                Since we are not good in Java, we just process the KPGN without
                checking for legal move or not.
                Now, all we need is ftp SDK in C to do the download. I'd been
                searching the Internet for a free ftp SDK, but I could not
                find one yet. Until then, the player or server have to use other
                ftp program to do the job.


                Thomas 'PointedEars' Lahn <PointedEars@we b.dewrites:
                Tuy Solang wrote:
                I download four scripts that are used to display
                Khmer PGN for Khmer Chess. It works fine with Netscape 7.1
                on MS Millenium, but it gave me an error(Java Script console)
                with Netscape 8.1 on MS XP. Here is the line :

                var pat_piece=/(\w{2}+)-(\w{2,3})/;

                I am familiar with C, but I have no clue with the above expression.

                Can someone help me to explain this expression?
                >
                It is an erroneous Regular Expression literal, and I would be surprised if
                there was no error in Netscape 7.1. `\w' specifies a word character, and
                the following `{2}' means two of them. Then follows a `+' which means the
                preceding expression must occur one or more times. However, the `{2}'
                quantifier must not be followed by the `+' quantifier. For a minimum number
                of characters you have to use the {n,} quantifier, with n being 2 here.
                >
                However, it is also possible that you were looking for `(\w{2})+' instead,
                which would mean one or more occurrences of two consecutive word characters,
                or that the `+' was meant literally (designating a check move) in which case
                it should have been `\w{2}\+'. It is not clear what exactly is meant here
                because AFAICS the matched string would not be a valid token as defined in
                the PGN Specification.
                >
                The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.


                >
                >
                PointedEars

                Comment

                • SAM

                  #9
                  Re: Java Script problems

                  Gregor Kofler a écrit :
                  SAM meinte:
                  >
                  >Question :
                  >how to do to get a word with a number pair of characters ?
                  >>
                  >(because I thought that '\w{2}+' was to do it)
                  >
                  /(\w{2})+/
                  That catches the first 2, 4, 6, 8, ..., letters of each word
                  BTW:
                  According to my Eclipse RegEx plugin /\w{2}+/ is accepted by JDK regular
                  expressions, but not by any of the other engines offered.
                  BBEdit prefers (\w{2})+

                  \W(\w{2})+.jpg

                  --/img1.jpg /img001.jpg /01.jpg "img2.jpg


                  --
                  sm

                  Comment

                  • Dr J R Stockton

                    #10
                    Re: Java Script problems

                    In comp.lang.javas cript message <uhche7roz.fsf@ verizon.net>, Tue, 15 Jan
                    2008 20:35:22, Tuy Solang <solang@verizon .netposted:
                    >
                    I download four scripts that are used to display
                    >Khmer PGN for Khmer Chess. It works fine with Netscape 7.1
                    >on MS Millenium, but it gave me an error(Java Script console)
                    >with Netscape 8.1 on MS XP. Here is the line :
                    >
                    var pat_piece=/(\w{2}+)-(\w{2,3})/;
                    >
                    >I am familiar with C, but I have no clue with the above expression.
                    >
                    >Can someone help me to explain this expression?

                    It gave you an error, which would have been some sort of message. That
                    message is supposed to guide you at least part-way towards determining
                    what that error is.

                    Therefore, you should have posted here the exact error message.



                    <FAQENTRY>
                    Section 2.3, which is too large and needs to be subdivided, needs to
                    say, at about paragraph 4, that where germane it is necessary to give
                    the exact error message (and an English translation) and a clear
                    indication of the alleged location of the error.

                    The final sentence of 2.3 para 1 is not sound English.

                    It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

                    --
                    (c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 IE 6
                    news:comp.lang. javascript FAQ <URL:http://www.jibbering.c om/faq/index.html>.
                    <URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
                    <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.

                    Comment

                    Working...