By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,573 Members | 938 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,573 IT Pros & Developers. It's quick & easy.

Java Script problems

P: n/a

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?
Jan 15 '08 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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/ >
Jan 15 '08 #2

P: n/a
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.

http://developer.mozilla.org/en/docs...Objects:RegExp
http://www.very-best.de/pgn-spec.htm
PointedEars
Jan 15 '08 #3

P: n/a
SAM
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_Expressions_in_JavaScript/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
Jan 15 '08 #4

P: n/a
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]
http://blog.netscape.com/2007/12/28/...-web-browsers/
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jan 16 '08 #5

P: n/a
SAM
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
Jan 16 '08 #6

P: n/a
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
http://www.regular-expressions.info/tutorial.html

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
Jan 16 '08 #7

P: n/a
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 <Po*********@web.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.

http://developer.mozilla.org/en/docs...Objects:RegExp
http://www.very-best.de/pgn-spec.htm
PointedEars
Jan 16 '08 #8

P: n/a
SAM
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
Jan 16 '08 #9

P: n/a
In comp.lang.javascript message <uh***********@verizon.net>, Tue, 15 Jan
2008 20:35:22, Tuy Solang <so****@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.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jan 16 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.