Page 1 of 1

Regular Expression Question~

Posted: Tue Nov 05, 2002 2:04 am
by akkassia
Like a forum system here, where you can write [ code ] and [ /code ]

to highlight your php sources whatever.

How can I do that?

I believe it requires some reg ex skills :)

I want to know how you can search [ code ] ..... [ /code ] and replace

with <table><tr><td> .... </td></tr></table>

thanks~

Posted: Tue Nov 05, 2002 2:24 am
by twigletmac
You can download the source code for this forum from http://www.phpbb.com and then I think there's a file called bbcode.php which contains the functions for parsing the messages.

Mac

Posted: Tue Nov 05, 2002 5:47 am
by DeGauss
If you *really* want to learn regexps, then you may need to look at some sites that offer an explanation as to how regexps work.

For simple stuff you probably want to stick with stuff like

"^Blah" = Anything that starts with "Blah"
"Blah$" = Anything that ends with "Blah"
"[^Blah]" = Does NOT begin with "Blah"

I think. It's too early to think about regexps.

It's ALWAYS too early to think about regexps.

Posted: Tue Nov 05, 2002 5:55 am
by fieldmethods
You're right, always too early ;)
But I'll try anyway.

"[^Blah]" = Does NOT begin with "Blah"

Actually, putting the carat (the ^ thingie) inside brackets like that will negate anything in that set. In other words, the carat has two meanings: outside of brackets, it means "at the beginning of the string" (like your first example), whereas INSIDE the brackets, it means "none of these."

So what you've go there would actually mean "Neither B, nor l, nor a, nor h."

Which would be a little odd :D

Cheers,
pat

Posted: Tue Nov 05, 2002 5:57 am
by DeGauss
I knew the carat thing wasn't right.

Maybe i meant [^"Blah"]

Bloody regexps.

Posted: Tue Nov 05, 2002 6:01 am
by volka

Posted: Tue Nov 05, 2002 6:05 am
by DeGauss
Isn't there some kind of difference between Perl Compatible regexps and regular regexps?

Again, bloody regexps.

Posted: Wed Nov 06, 2002 2:25 pm
by Rob the R
Definitely. Basic Regular Expressions don't include the "(?<!Blah)" solution that Perl and PHP can use. For BRE's (like an old-school UNIX grep), you'd need to specify something like "^[^B][^l][^a][^h]" to return lines not beginning with "Blah".