By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,409 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,409 IT Pros & Developers. It's quick & easy.

Wrong Pattern for match_count function

P: n/a
Hi all there,

Sorry for this newbee question but how comes that the following
pattern: $r = "%<td valign=top><a href=\"([^>]+?)\"(.*?)>%";

does not return any result, while the pattern:
$r = "%<a href=\"([^>]+?)\"(.*?)>%";

returns me results, but too many (that's why I wanted to use the first
pattern, without any luck).

Called function: $match_count = preg_match_all ($r, $pdata, $items);

Example of $pdata:
<td width=80 align=center valign=top><a href="<link that should not be
grabbed by the pattern>" id=r><img src=image.jpg width=66 height=79
alt="" border=1><br><font size=-2>Bla Bla text</font></a></td><td
valign=top><a href="<link that should be grabbed by the pattern>"
id=r>Bla bla text</a><br>

Can Anyone help, please?

Thanks.
Fabian

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Am Mo 09.05.05 um 16:25 CEST schrieb "Fabian" <ne******@hotmail.com>:
Hi all there,

Sorry for this newbee question but how comes that the following
pattern: $r = "%<td valign=top><a href=\"([^>]+?)\"(.*?)>%";

does not return any result[...]

Example of $pdata:
<td width=80 align=center valign=top><a href="[...]

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
How should this match against "<td valign=top>"? You may try the correct
<td> line or something like (untested)
%<td[^>]*><a href=\"([^>]+?)\"(.*?)>% as pattern.

stefan
Jul 17 '05 #2

P: n/a

Stefan Heinrichsen wrote:
Am Mo 09.05.05 um 16:25 CEST schrieb "Fabian" <ne******@hotmail.com>:
Hi all there,

Sorry for this newbee question but how comes that the following
pattern: $r = "%<td valign=top><a href=\"([^>]+?)\"(.*?)>%";

does not return any result[...]

Example of $pdata:
<td width=80 align=center valign=top><a href="[...] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
How should this match against "<td valign=top>"?


Thanks for your reply Stefan,

How should it not? Sorry, I am probably wrong, but I am not familiar
with regexp and reading the rules...does not help me, in this case

I need to distinguish this string:
"<td valign=top><a href...." by this one
"<td width=80 align=center valign=top><a href...."

I need to match the first and not the second.

You may try the correct <td> line or something like (untested)
%<td[^>]*><a href=\"([^>]+?)\"(.*?)>% as pattern.


BTW, this does not match any pattern at all. (why? shouldn't it return
any "<td...><a href...>" pattern? it's not what I want, however....)

If you could clarify. Many thanks.
Cheers,
Fabian

Jul 17 '05 #3

P: n/a
Am Mo 09.05.05 um 23:23 CEST schrieb "Fabian" <ne******@hotmail.com>:

Stefan Heinrichsen wrote:
Am Mo 09.05.05 um 16:25 CEST schrieb "Fabian"
<ne******@hotmail.com>:
Hi all there,

Sorry for this newbee question but how comes that the following
pattern: $r = "%<td valign=top><a href=\"([^>]+?)\"(.*?)>%";

does not return any result[...]

Example of $pdata:
<td width=80 align=center valign=top><a href="[...]

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
How should this match against "<td valign=top>"?


Thanks for your reply Stefan,

How should it not? Sorry, I am probably wrong, but I am not familiar
with regexp and reading the rules...does not help me, in this case

I need to distinguish this string:
"<td valign=top><a href...." by this one
"<td width=80 align=center valign=top><a href...."

I need to match the first and not the second.


Oh sorry my fault. I don't read you $pdata exactly. Is $pdata a exactly
copy or is it possible that there are any whitespace or somethingelse
you may forgot?

stefan
Jul 17 '05 #4

P: n/a

Stefan Heinrichsen wrote:

Oh sorry my fault. I don't read you $pdata exactly. Is $pdata a exactly copy or is it possible that there are any whitespace or somethingelse
you may forgot?


It should be the exact copy of what it should be, however I hope to be
able to add any whitespace information: "\s+" if this would be the
case.

Thanks for your help.

Fabian

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.