Welcome to WebmasterWorld Guest from 54.166.107.51

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Regex Question

regular expressions in php

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

Full Member

10+ Year Member

joined:Apr 8, 2004
posts:215
votes: 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>?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 27, 2001
posts:2548
votes: 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>%

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

Full Member

10+ Year Member

joined:Apr 8, 2004
posts:215
votes: 0


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

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

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

Preferred Member

10+ Year Member

joined:Oct 1, 2004
posts:607
votes: 0


question mark is important:

<p[^>]*?>
12:12 am on Apr 5, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 27, 2001
posts:2548
votes: 0


Yes, even <p.*?> should do it.
12:13 am on Apr 5, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 27, 2001
posts:2548
votes: 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.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members