473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

preg_match_all help wanter

Hello, as a newbie I'm requesting some help in understanding the regular
expression below

preg_match_all("|<tr(.*)</tr>|U",$table,$rows);

Would anybody please just run through ("|<tr(.*)</tr>|U" from left to right
and tell me what it means?

Thanks
Paul Bird

--
Add an underscore after the p to reply
Mar 22 '08 #1
6 2429
PaulB:
preg_match_all("|<tr(.*)</tr>|U",$table,$rows);
| are delimiters.
<tr are literal characters.
..* matches zero or more of any character except new lines
() makes a capturing subpattern
</trare literal characters
U inverts the Greediness of the whole pattern, meaning in this case
that .* stops the minute it reaches the first </tror newline instead
of matching everything until the last </tror newline.

This looks like an attempt to capture rows from an HTML table.

--
Jock
Mar 22 '08 #2
John Dunlop wrote:
PaulB:
>preg_match_all("|<tr(.*)</tr>|U",$table,$rows);
>are delimiters.
<tr are literal characters.
.* matches zero or more of any character except new lines
() makes a capturing subpattern
</trare literal characters
U inverts the Greediness of the whole pattern, meaning in this case
that .* stops the minute it reaches the first </tror newline instead
of matching everything until the last </tror newline.

This looks like an attempt to capture rows from an HTML table.
Thank you very much. Yes it is an attempt to capture rows from an HTML
table, I am screen scraping a website to an array, however despite a
websearch I could not find a single clear reference to the preg_match_all
parameters so I appreciate your reply.

Paul
--
Add an underscore after the p to reply
Mar 22 '08 #3
On Sat, 22 Mar 2008 14:50:38 +0100, PaulB <pb***@ntlworld.comwrote:
John Dunlop wrote:
>PaulB:
>>preg_match_all("|<tr(.*)</tr>|U",$table,$rows);
>>are delimiters.
<tr are literal characters.
.* matches zero or more of any character except new lines
() makes a capturing subpattern
</trare literal characters
U inverts the Greediness of the whole pattern, meaning in this case
that .* stops the minute it reaches the first </tror newline instead
of matching everything until the last </tror newline.

This looks like an attempt to capture rows from an HTML table.

Thank you very much. Yes it is an attempt to capture rows from an HTML
table, I am screen scraping a website to an array, however despite a
websearch I could not find a single clear reference to the preg_match_all
parameters so I appreciate your reply.

http://www.php.net/preg_match_all
http://nl2.php.net/manual/en/referen...ern.syntax.php
http://www.regular-expressions.info/

And using regular epressions on HTML is notthe best way to go. Sure, if
you know what you're doing, and the HTML is valid, it could work most of
the time. It's more a job for a parser though, those are much more robust
& reliable for this kind of thing.
--
Rik Wasmus
Mar 22 '08 #4
Rik Wasmus wrote:
On Sat, 22 Mar 2008 14:50:38 +0100, PaulB <pb***@ntlworld.comwrote:
<snip>
>
http://www.php.net/preg_match_all
http://nl2.php.net/manual/en/referen...ern.syntax.php
http://www.regular-expressions.info/

And using regular epressions on HTML is notthe best way to go. Sure,
if you know what you're doing, and the HTML is valid, it could work
most of the time. It's more a job for a parser though, those are much
more robust & reliable for this kind of thing.
I got started with http://www.bradino.com/php/screen-scraping/ which strikes
me a very clear and succint example, however understanding the regex is a
little harder.

Paul
Mar 22 '08 #5
In article <64*************@mid.individual.net>, pb***@ntlworld.com
says...
Rik Wasmus wrote:
On Sat, 22 Mar 2008 16:03:16 +0100, PaulB <pb***@ntlworld.comwrote:

Regular exspressions should never be used in any application anyone other
than the original author would ever see and only then if he never has to
look at it more than three days later....
Mar 24 '08 #6
Greetings, if***@thinkaboutit.it.
In reply to Your message dated Monday, March 24, 2008, 17:49:23,
Regular exspressions should never be used in any application anyone other
than the original author would ever see and only then if he never has to
look at it more than three days later....
ROFLOL! Thanks for the happy morning, dude!
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Jun 2 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Han | last post by:
Determining the pattern below has got my stumped. I have a page of HTML and need to find all occurrences of the following pattern: score=9999999999&amp; The number shown can be 5-10 characters...
2
by: Han | last post by:
I'm wondering if someone can explain why the following works with preg_match_all, but not preg_match: $html = "product=3456789&amp;" preg_match_all ("|product=(\d{5,10})&amp;|i", $html, $out); $out...
3
by: Han | last post by:
I know this is possible (because preg can do almost anything!), but can't get a handle on the syntax. I have an HTML string: <font size="3"><a...
5
by: Han | last post by:
Using preg_match_all, I need to capture a list of first and last names plus an optional country code proceeding them. For example: <tr><td>AU</td><td>Jane Smith</td></tr>...
2
by: Han | last post by:
The following pattern (which is one subpattern in a string of several) looks for the following $xxx,xxx.xx (with the dollar sign) or xxx,xxx.xx (space in replace of missing dollar sign) ...
0
by: petrovitch | last post by:
While using the following loop to extract images from the google search engine I discovered that preg_match_all works much faster parsing small strings in a loop than extracting all of the urls at...
10
by: greatprovider | last post by:
i'm starting with a string such as "Na**3C**6H**5O**7*2H**20" im attempting to match all **\d+ ...once i can match all the double asterix \d i intend to wrap the \d in "<sub>" tags for display...
1
by: ngmr80 | last post by:
Hi, I'm experiencing a problem when trying to capture substrings with preg_match_all() from strings like "set('Hello','World')" using the following Regular Expression (PERL syntax): ...
2
loriann
by: loriann | last post by:
hi, I have a problem with preg_match function returning empty arrays for my wonderful regexes. However, I can't see what I am doing wrong - maybe one of you could help? I'm loading the source...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.