U
Uldis Bojars
Hi All,
I have encountered problems with JS RegExp.exec() and can't find what
is the problem. Could you help me?
formRequest is a function that extracts some information from
XMLHTTPRequest response. A very strange effect (and I can't find where
I've done something wrong) is that regexp matches in this function fail
on every second call.
Contents of the 'response' variable are similar in all calls and I
tested with javascript regexp evaluator that there is a match for these
regexped in the response text. Nevertheless JS returns null.
function formRequest( response )
{
var re = /<input type=hidden name="([^"]*)" value="([^"]*)">/g;
var m2 = re.exec( response );
alert(m2);
var re = /<input src="([^"]*)" border="([^"]*)"
height="([^"]*)" type="image" width="([^"]*)" name="([^"]*)"
value="([^"]*)">/g;
var m3 = re.exec( response );
alert(m3);
}
A simple workaround is to check if exec() returns null and do the
request again:
if (m2 == null)
m2 = re.exec( response );
This helps and then the problem shifts to "var m3 = re.exec( response
);" which can be fixed in a similar manner.
While this fixes the problem somehow it is not acceptable that a
program (or JavaScript?) behaves in this seemingly unrational way and
I'd like to get it working properly.
P.S. Script is being executed from a XUL extension in Mozilla Firefox
1.5.
Thanks,
Uldis
[ http://captsolo.net/info/ ]
I have encountered problems with JS RegExp.exec() and can't find what
is the problem. Could you help me?
formRequest is a function that extracts some information from
XMLHTTPRequest response. A very strange effect (and I can't find where
I've done something wrong) is that regexp matches in this function fail
on every second call.
Contents of the 'response' variable are similar in all calls and I
tested with javascript regexp evaluator that there is a match for these
regexped in the response text. Nevertheless JS returns null.
function formRequest( response )
{
var re = /<input type=hidden name="([^"]*)" value="([^"]*)">/g;
var m2 = re.exec( response );
alert(m2);
var re = /<input src="([^"]*)" border="([^"]*)"
height="([^"]*)" type="image" width="([^"]*)" name="([^"]*)"
value="([^"]*)">/g;
var m3 = re.exec( response );
alert(m3);
}
A simple workaround is to check if exec() returns null and do the
request again:
if (m2 == null)
m2 = re.exec( response );
This helps and then the problem shifts to "var m3 = re.exec( response
);" which can be fixed in a similar manner.
While this fixes the problem somehow it is not acceptable that a
program (or JavaScript?) behaves in this seemingly unrational way and
I'd like to get it working properly.
P.S. Script is being executed from a XUL extension in Mozilla Firefox
1.5.
Thanks,
Uldis
[ http://captsolo.net/info/ ]