REGULAR EXPRESSION HELP
| From: | John | Date: | Sat, 12 Jul 2003 06:31:18 +0000 |
| Subject: | REGULAR EXPRESSION HELP | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-154935@lists.php.net to get a copy of this message | ||
Hi,
I'm pretty new to regular expressions. Before, I used to write long-winded
and buggy segments of code with PHPs string functions to extract text. But I
want to learn how to use perl reg-ex as it seems useful to know so I ordered
"Mastering Regular Expressions". But it hasn't come yet so I'm asking for
help...
I need to match a pattern, not in a single-line but from a HTML page, which
obviously has loads of lines. I need to match 2 lines from this HTML page:
1) <HTML><TITLE>FirstVariable - Second Variable</TITLE></HTML>........
2) <TABLE><TD><TR>(newline)
ThirdVariable</TR></TD></TABLE>...
I tried this code:
1) preg_match("/<HTML><TITLE>(\S+) - (\S+)</TITLE></HTML>/",
$html_page,
$variables);
2)
preg_match("/<TABLE><TD><TR>\n(\S+)</TR></TD></TABLE>/",
$html_page,
$variables);
The first 2 variables are matched into the $variables array but not the
third one. Sometimes when the third one is matched, it starts from where I
want it to start but takes all the text to the end of the HTML document!
Any ideas? Is there any characters that I should have escaped that I
didn't?? All I can think of is that because the first line that I want to
match is on the FIRST LINE of the html page, that matches. But reg-ex can't
handle the next line as its way down the page????
TIA