473,804 Members | 3,067 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2443
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_al l("|<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.individua l.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***@thinkabou tit.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*******@free mail.ru>

Jun 2 '08 #7

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

Similar topics

4
3805
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 in length. I would like to extract only the number, stripping off the "score=" and "&amp;".
2
4698
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 = 3456789 preg_match ("|product=(\d{5,10})&amp;|i", $html, $out);
3
7297
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 href="http://www.example.com?product=3456789&amp;company=3528"> Mickey Mouse</a></font><br><img width="200" height="200" border="0" src="http://www.example.com/images/3456789.jpg"><b>$8.00</b>
5
6098
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> <tr><td></td><td>Bill Johnson</td></tr> <tr><td>GB</td><td>Larry Brown</td></tr> <tr><td>US</td><td>Mary Jordon</td></tr> <tr><td></td><td>Peter Jones</td></tr>
2
2389
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) It works great WITHOUT a ? quantifier
0
1482
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 once from a much larger string. This surprised me because I expected the preg_match_all to perform the task much faster. Why is this, and is there an easier way to resolve this matter? for ($i = 0; $i < $m; $i++, $start+=20){
10
2045
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 purposes. i have been trying to write the correct pattern for 2 weeks now without any success...i can get preg_replace() to work, with several simple patterns but when i use preg_match_all, i either get unintended results or incomplete matches.
1
1950
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): "/^set\((?:'(+)'(?(?!\)),))+\)$/"
2
8269
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 of a website into variable and then using preg_match_all to extract all occurrences of a string. it looks like this (where source code is loaded into $page variable): preg_match ('/<div\s+?id="srNum_\d+?"\s+?class="number">(.*?)<\/div>/', $page,...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9152
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.