Welcome to WebmasterWorld Guest from 54.204.165.156

Forum Moderators: coopster & jatar k

Regex Question

regular expressions in php

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

10+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



%<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)

10+ Year Member



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

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

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

10+ Year Member



question mark is important:

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

WebmasterWorld Senior Member 10+ Year Member



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

WebmasterWorld Senior Member 10+ Year Member



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month