W
weston
Has anyone ever encountered trouble with regular expressions not
capturing matches specified by parentheses? I seem to have a weird
situation where a regular expression is matching the String I'm running
it against, but none of the parenthized expressions are coming back in
the array.
I'm basically trying to pull a topic out of a bulletin board page. So
I'll run:
var bodystr = new
String(document.getElementsByTagName('body')[0].innerHTML)
;
var topicPattern = /<p style="margin-left: 4px;"><b><font
face="Arial" size=
"2">(.*?)<\/font><\/b><\/p>/ig;
var matches = bodystr.match(topicPattern);
And here's the weird thing. Apparently, matches[0] is filled, with the
string that matches the whole pattern....
But there's nothing in matches[1]. Also nothing in RegExp.$1.
Am I misunderstanding how this is supposed to work, or is there
something genuinely odd about this?
If anyone wants to see this in context, here's an example:
http://mmedia.csoft.net/LE/testpage.html
Click the link in the upperhand corner to see it in action. Feel free
to poke around that directory, too.
capturing matches specified by parentheses? I seem to have a weird
situation where a regular expression is matching the String I'm running
it against, but none of the parenthized expressions are coming back in
the array.
I'm basically trying to pull a topic out of a bulletin board page. So
I'll run:
var bodystr = new
String(document.getElementsByTagName('body')[0].innerHTML)
;
var topicPattern = /<p style="margin-left: 4px;"><b><font
face="Arial" size=
"2">(.*?)<\/font><\/b><\/p>/ig;
var matches = bodystr.match(topicPattern);
And here's the weird thing. Apparently, matches[0] is filled, with the
string that matches the whole pattern....
But there's nothing in matches[1]. Also nothing in RegExp.$1.
Am I misunderstanding how this is supposed to work, or is there
something genuinely odd about this?
If anyone wants to see this in context, here's an example:
http://mmedia.csoft.net/LE/testpage.html
Click the link in the upperhand corner to see it in action. Feel free
to poke around that directory, too.