P
passion_to_be_free
I am writing a javascript that will make an http request, sort through
the html for any links on the page, and then store them for future
processing.
To test things, I pasted html source code into my text editor, ran a
GREP search using the following regular expression:
(<a [^>]*href\s*=\s*")([^"]+)("[^>]*>)
And the appropriate links were highlighted correctly. I then
implemented this regular expression into my javascript. However, the
javascript only matched one out of 10 links on the page I was
searching. Can anyone
(a.) tell me what's wrong with my regular expression
(b.) suggest a better one?
Here's my javascript code. I've even tried it two ways (as you'll see
by the commented code):
// make the page request
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET",querystring,false);
xmlhttp.send(null);
//just to verify I'm getting something back:
//document.write(xmlhttp.responseText);
}
var htmltext = xmlhttp.responseText;
//Method 1:
//create a pattern matcher and execute it
var reg = new RegExp("");
reg.compile('(<a class=l [^>]*href\s*=\s*")([^"]+)("[^>]*>)');
var searchresults = reg.exec(htmltext);
//Method 2:
//use the string.match() function
//var searchresults = htmltext.match('(<a class=l
[^>]*href\s*=\s*")([^"]*)("[^>]*>)');
the html for any links on the page, and then store them for future
processing.
To test things, I pasted html source code into my text editor, ran a
GREP search using the following regular expression:
(<a [^>]*href\s*=\s*")([^"]+)("[^>]*>)
And the appropriate links were highlighted correctly. I then
implemented this regular expression into my javascript. However, the
javascript only matched one out of 10 links on the page I was
searching. Can anyone
(a.) tell me what's wrong with my regular expression
(b.) suggest a better one?
Here's my javascript code. I've even tried it two ways (as you'll see
by the commented code):
// make the page request
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET",querystring,false);
xmlhttp.send(null);
//just to verify I'm getting something back:
//document.write(xmlhttp.responseText);
}
var htmltext = xmlhttp.responseText;
//Method 1:
//create a pattern matcher and execute it
var reg = new RegExp("");
reg.compile('(<a class=l [^>]*href\s*=\s*")([^"]+)("[^>]*>)');
var searchresults = reg.exec(htmltext);
//Method 2:
//use the string.match() function
//var searchresults = htmltext.match('(<a class=l
[^>]*href\s*=\s*")([^"]*)("[^>]*>)');