regex paterns

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

regex paterns

Post by ddragas »

this is main pattern into web page (html)

Code: Select all

<td id=type>Type_is_important</td><td>|</td><td><a href="link_is_not_important" target=a>Description_of_link_is_important</a></td>
Now what I want to acomplish is to check if "Type" is something than return link, and if Description of link is something return link.

If someone can check for me if I've putted good patterns


Code: Select all

$glavni_pattern = "<td id=type>\"^[\"]*\"</td><td>|</td><td><a href=\"^[\"]*\" target=a>\"^[\"]*\"</a></td>";
$pattern_za_link= "HREF=\"[^\"]*\"";
$pattern_za_opis= "\"^[\"]*\"</a>";
$patern_za_vrstu = "type>\"^[\"]*\"</td>";
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You have this a few times:

Code: Select all

^[...]

It should be this:

Code: Select all

[^...]
Outside of the character class, it's just a character I believe.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Regex patterns? :arrow: Regex. :roll:
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

thank you for reply

one more thing

what regex should I use to get all data between "<tr" and "</tr>"

tried to use "/<tr[^\"]*\<\/tr>/" but with no sucsess

using preg_match_all

here is all code

Code: Select all

$url = file_get_contents("some_url");

preg_match_all( "/<tr[^\"]*\<\/tr>/" ,  $url, $red, PREG_SET_ORDER);

print_r ($red);
thank you

regards
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

preg_match_all( "/<tr>.*?<\/tr>/i" ... );
Keep things simple :wink:
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

thank you

regards
Post Reply