regex exclude <font> inside <font>

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

Moderator: General Moderators

Post Reply
mesutsahin
Forum Newbie
Posts: 10
Joined: Wed Feb 08, 2006 3:14 am

regex exclude <font> inside <font>

Post by mesutsahin »

I want it to match this

Code: Select all

<font size="4">some text or some tags</font>
but I dont want it to match this.

Code: Select all

<font size="4">some text <font size="4>some text</font>dfssdfsdddf</font>
What I want is that I dont want any font tag including another font inside.

Code: Select all

<font size="4">some text or some tags excluding font tag</font>

I tried this.

Code: Select all

/(<font size="\d+">)(?!<font)(.*?)(<\/font>)/i
this works only when the text inside the font tags doesn't start with font. But when the font is in the middle or at the end, it doesn't work.
I have read about the exclusion patterns. But I couldn't make them work for me.
Please help me. Thanks....
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post by printf »

How are you using this, it can be done a few ways, but that depends on where your using it! The reason I say that, is because using it in preg_match(), preg_match_all() or preg_replace_callback() would need a little different format to match, return or remove exactly what you want. You could use (1) format, but then you will capture stuff you don't really need, which makes you have to do more processing! Give an example of the exact usage and I will write the regex to do what your wanting!


me!
mesutsahin
Forum Newbie
Posts: 10
Joined: Wed Feb 08, 2006 3:14 am

Post by mesutsahin »

I have to use preg_match here. I need an array of the font tags that don't contain other fonts inside.
Post Reply