Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-18-2002, 01:12 AM   PM User | #1
dmittner
New to the CF scene

 
Join Date: Jul 2002
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
dmittner is an unknown quantity at this point
Regular Expression Help

I'll be the first to admit that I suck with regular expressions. I consider myself to be pretty good in Perl, but for some reason the understanding of them have eluded me. I'm working on a BBS which has various internal codes which translate into the appropriate HTML when displayed, as most BBS's do in one form or another. The thing I'm working with makes an exception in the usual substitution.

So far I have this:

Code:
while ( $$text =~ /\[codes\].*?\[.*?\[\/codes\]/ || $$text =~ /\[codes\].*?\].*?\[\/codes\]/ ){
    $$text =~ s!\[codes\](.*?)\[(.*?)\[/codes\]!\[codes\]$1\&\#091;$2\[/codes\]!gi;
    $$text =~ s!\[codes\](.*?)\](.*?)\[/codes\]!\[codes\]$1\&\#093;$2\[/codes\]!gi;
}
Ironically, what I'm attempting to do is exactly what this BBS's 'code' tag does. The problem I'm having is that if I have multple code couples in the post, it deactivates all codes between the first open code tag and the last close code tag.

First.. is there anyway to avoid the while loop? I'm sure there is and it's probably something simple that I'm overlooking. Secondly, how to I have it stop the replacement at the first end code tag reached after the open tag?

Thanks in advance,
Dave Mittner
So-called programmer
dmittner is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:58 AM.


Advertisement
Log in to turn off these ads.