|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Complex pattern matching
I need help... I'm writing a subroutine to convert html to BBcode... and it's not quite working...
Since it contains BBcode, I can't post the code directally here... however I will post a link to it. http://gms.uoe.org/html2bb.txt Anyone that can help, please do! |
|
#2
|
|||
|
|||
|
What you need to do is change your thinking a bit.
You are thinking of the html and BB tags as one item, but you can think of them as seperate tags. Instead of making a list where each element contains the start and end tag, make a list that has start and end tags as seperate elements. That way you can deal with nested html code without extra coding. -- Ian |
|
#3
|
|||
|
|||
|
Yes well
I still need to be able to grab the URLs from <A> tags and perhaps the colors from <FONT> etc... so I still need to be able to capture + print...
![]() |
|
#4
|
|||
|
|||
|
http://expert.cc.purdue.edu/~coultejk/temp/tmp.txt
This is obviously untested code here (I just wrote it, and havn't tried it), but it should give you an idea of where you can go with it. |
|
#5
|
|||
|
|||
|
Thanks
I was hopeing to be able to keep them in the same hash, but I guess I'll need to pull them out.
I read in Programming Perl something that led me to believe that I could do that sucessfully using qr// So... umm... was I way off, or just not using it right? Is there a way to keep them in the hash listing and still do what I want it to do? |
|
#6
|
|||
|
|||
|
Ok, I think this SHOULD work, but it doesn't... the hash remains the same as it is in the above link
Code:
foreach $KEY (keys %TAGLIST){
while($text =~ m/$KEY/g){
local $replace = '';
eval(qq~\$replace = "$TAGLIST{$KEY}"~);
die "$@ \nFailed String:$TAGLIST{$KEY}" if($@);
$text =~ s/$&/$replace/;
}
}
I now get this error: Search pattern not terminated at (eval 6) line 1 Failed String:[U-RL=$1]$2[/U-RL] at testhtml.cgi line 31 (Remove the - in between U and RL) I know I'm on the right track.. but I'm missing something... I sucessfully tested the majority of it with a seperate program Code:
$TAGLIST = 'Hi $KEY';
$KEY = 'John';
eval("\$prep = \"$TAGLIST\"");
die $@ if($@);
print $prep;
The one I just listed works... so what did I miss? ![]() |
|
#7
|
|||
|
|||
|
I DID IT!
I solved my problem... and it was so simple! Code:
foreach $KEY (keys %TAGLIST){
eval("\$text =~ s/$KEY/$TAGLIST{$KEY}/gis;");
die "$@ \n Failed String: $TAGLIST{$KEY}" if($@);
}
YEY!! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Complex pattern matching |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|