Welcome to WebmasterWorld Guest from 54.160.131.144

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Regex Question

regular expressions in php

     

ncreegan

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>?

physics

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

ncreegan

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?

zCat

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

10+ Year Member



question mark is important:

<p[^>]*?>

physics

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

WebmasterWorld Senior Member 10+ Year Member



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

physics

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.