Regular Expressions and a question of sanity

C

Chris McKay

Could anyone explain what's going on here? I'm going nuts.

I pull some text from an XML file and store it in a Javascript object
(config.CopyRule.TargetFileNameRegExp). For some reason I can't use it in a
JS RegExp constructor. I've tried a million things but still can't work out
what is going on:

Using Microsoft (R) Windows Script Host Version 5.6

var abc = "MARS_25Oct05_20.38.txt";
//var def = new String((config.CopyRule.TargetFileNameRegExp).toString());
// also fails
var def = new String(config.CopyRule.TargetFileNameRegExp);
logMessage(DEBUG, "def=:"+def+":");

var ghi = new String("^.+\\.txt$");
var xyz = new RegExp(def);
if (xyz.test(abc)) {
logMessage(DEBUG, "Match");
}
else {
logMessage(DEBUG, "No Match");
}
xyz.compile(def.toString());
if (xyz.test(abc)) {
logMessage(DEBUG, "Match");
}
else {
logMessage(DEBUG, "No Match");
}
xyz.compile(ghi);
if (xyz.test(abc)) {
logMessage(DEBUG, "Match");
}
else {
logMessage(DEBUG, "No Match");
}
xyz.compile("^.+\\.txt$");
if (xyz.test(abc)) {
logMessage(DEBUG, "Match");
}
else {
logMessage(DEBUG, "No Match");
}

Results in
def=:^.+\\.txt$:
No Match
No Match
Match
Match
 
C

Chris McKay

Don't you love it when you post and then solve the problem in the next five
minutes?

So I made the XML file string "^.+\.txt$" instead of "^.+\\.txt$" ...

And all works ...

C
 
E

Evertjan.

Chris McKay wrote on 16 nov 2005 in comp.lang.javascript:
Don't you love it when you post and then solve the problem in the next
five minutes?

Not when you are multiposting!!!!
 
C

Chris McKay

I'm a little confused about this response?

Are you objecting to my post in microsoft.public.scripting.jscript?

C
 
E

Evertjan.

Chris McKay wrote on 17 nov 2005 in comp.lang.javascript:

[please do not toppost on usenet]
I'm a little confused about this response?
"?"?

Are you objecting to my post in microsoft.public.scripting.jscript?

Not at all, only to multiposting there and here.
Please crosspost instead if necessary.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Thu, 17
Nov 2005 09:19:08, seen in Evertjan.
Chris McKay wrote on 17 nov 2005 in comp.lang.javascript:

[please do not toppost on usenet]
I'm a little confused about this response?
"?"?

Are you objecting to my post in microsoft.public.scripting.jscript?

Not at all, only to multiposting there and here.
Please crosspost instead if necessary.

Those who correctly understand the meanings of cross-post and multi-post
will generally post correctly. So one should not assume that those who
post incorrectly will understand comments such as yours. Since the rest
of us prefer not to read repeated explanations here, the best thing is
to provide a suitable link, to FAQ 2.3 para 6, as below, or otherwise.

Being Dutch does not entitle you to believe that those with English, or
even Scottish, names are more fluent in English than you are!
 
E

Evertjan.

Dr John Stockton wrote on 18 nov 2005 in comp.lang.javascript:
Being Dutch does not entitle you to believe that those with English, or
even Scottish, names are more fluent in English than you are!

Whether I am Dutch or not entitles me to believe whatever I believe,
since while believing something is or should be the result of thought,
that result cannot be changed by expediency.

btw, in Dutch gentry, there where [are?] people called:

Baron MacKaay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top