Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching [forum style] tags with regexes 2

Status
Not open for further replies.

Leozack

MIS
Oct 25, 2002
867
GB
Hey guys. I've spent hours today working the impossible trying to do the simple. Normal coding affair.
What I've got is text input where I've chosen to except certain forum styles of formatting, aka
Code:
[heading]This Is A Heading[/heading]
[linebreak]
[b]Bold text here[/b] [i]Italic text here[/i] [u]Underlined text here[/u]
[colour='red']Coloured text here[/colour] (colour from red/blue/yellow/purple/green/orange/white/black)
[size='1']Small text here[/size] (size from 1-10)
[link='[URL unfurl="true"]http://www.test.com'[/URL]]Click here[/url]
[email='address']Email us[/email] (will goto 'address')
Exactly like the code tags I just used.

This is somewhat like the post over at
Currently I have it working fine for the easy ones etc, but for complicated tags like colour/size/link/email it gets fiddly. I have it working if I replace the first tag seperately from the last, eg
Code:
$thetext = ereg_replace("\[colour='([^']+)']","<font color=\"\\1\">",$thetext);
$thetext = ereg_replace("\[/colour]","</font>",$thetext);
But me being me I stubbornly wanted to do it all in 1 go. But nowhere can I find a way to specify the section in the middle of the pattern (the bits between the tags to be formatted) to be "any char but NOT the closing tag sequence eg [/colour]".

For example, since it's greedy patterning, this will format from the first opening tag to the last closing tag
Code:
$thetext = ereg_replace("\[colour='([^']+)'](.+)\[/colour]","<font color=\"\\1\">\\2</font>",$thetext);
Now I've tried making that crucial middle bit (.+) into all sorts, but I just can't get it to look for the closing tag, thanks to [ and ] being stuff to do with patterns. Typical eh?

Please help! ;_;

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
I don't like to bump my own posts but I must add that
Code:
/(\[center\])(.+)(\[\/center\])/im
makes no difference :/

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top