homepage Welcome to WebmasterWorld Guest from 54.234.147.84
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Regex Question
regular expressions in php
ncreegan




msg:1288356
 10:55 pm on Apr 4, 2006 (gmt 0)

Just when I thought I was getting the hang of PHP/Perl regular expressions...

why is %<p[^>](.*)</font>%Uis

not matching anything in the chunk:

<p>this is a test paragraph with some bad html <font size=-3>small text</font>...

Shouldn't preg_match_all be grabbing everything between <p> and </font>?

 

physics




msg:1288357
 11:00 pm on Apr 4, 2006 (gmt 0)

%<p[^>](.*)</font>%
Won't work because you're saying
"match <p then one not > then grab anything between not > and </font>"
This won't work because you have <p>.

I think you want
%<p>(.*?)</font>%

ncreegan




msg:1288358
 11:05 pm on Apr 4, 2006 (gmt 0)

I'm wanting to match <p> or <p class>...

would <p[^>]*>... do it?

zCat




msg:1288359
 11:35 pm on Apr 4, 2006 (gmt 0)

question mark is important:

<p[^>]*?>

physics




msg:1288360
 12:12 am on Apr 5, 2006 (gmt 0)

Yes, even <p.*?> should do it.

physics




msg:1288361
 12:13 am on Apr 5, 2006 (gmt 0)

btw, the? means "don't be greedy", i.e. stop at the first instance you see of the following character, not the last instance you see.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved