Regular Expression Question~

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
akkassia
Forum Newbie
Posts: 4
Joined: Sun Oct 13, 2002 10:52 am
Location: China

Regular Expression Question~

Post 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~
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
DeGauss
Forum Contributor
Posts: 105
Joined: Tue Oct 22, 2002 9:44 am
Location: Gainesville, FL

Post 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.
fieldmethods
Forum Newbie
Posts: 1
Joined: Tue Nov 05, 2002 5:55 am
Contact:

Post 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
DeGauss
Forum Contributor
Posts: 105
Joined: Tue Oct 22, 2002 9:44 am
Location: Gainesville, FL

Post by DeGauss »

I knew the carat thing wasn't right.

Maybe i meant [^"Blah"]

Bloody regexps.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

DeGauss
Forum Contributor
Posts: 105
Joined: Tue Oct 22, 2002 9:44 am
Location: Gainesville, FL

Post by DeGauss »

Isn't there some kind of difference between Perl Compatible regexps and regular regexps?

Again, bloody regexps.
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post 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".
Post Reply