Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm really at a dead end with this :(

Here is an example variable ($test_string);

my $test_string = q| [lien "http://www.domain.com"][img]http://www.domain.com/image.gi +f[/img][/lien] Si qqn connait un transporteur ou une agence qui fais des bon prix [lien "http://www.smileycentral.com/?partner=ZSzeb001"][img]http://smi +leys.smileycentral.com/cat/12/12_1_220.gif[/img][/lien] pour l'australie je suis preneur merci............... BONNE ANNÉE [signature]|;


Now, what I need to do, is get rid of the lien .. /lien around that code. I've been trying for ages to simply get code that will work .. this:

while ($test_string =~ m%\[img\]([0-9a-zA-Z\"\?\%\:\/\_\-\.\=]+)\[/img\]%gix) {

..works fine (and grabs the image URL's fine).

However, when doing something like:

while ($test_string =~ m%\[lien "([0-9a-zA-Z\"\?\%\:\/\_\-\.\=]+)"\]\[img\]([0-9a-zA-Z\"\?\%\:\/\_\-\.\=]+)\[/img\]%gix) {

..it simply refuses to match at all.

Can anyone suggest where I'm going wrong, or better yet - a simpler way to get rid of the lien stuff from around [img tags?

TIA!

Andy

Replies are listed 'Best First'.
Re: BBCodes, removing [URL's
by moritz (Cardinal) on Apr 23, 2009 at 14:11 UTC
    You can get Parse::BBCode to recognize that tag, manipulate the parse tree (ie removing the items you don't want) and turn it into a string again with ->raw_text.

    That way you'll have proper parsing, and don't have to require on some regexes that might work most of the time, but where you'd never be sure if you didn't forget some cases.

      Thanks, will check that out :)

      Cheers

      Andy
      Man, been playing with this for ages, and still not got it doing what I want :@

      Any suggestions?

      TIA

      Andy
        What have you tried? From the documentation it doesn't seem too hard to add custom tags - did you manage that? If not, where did you fail?