in reply to BBCodes, removing [URL's

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.

Replies are listed 'Best First'.
Re^2: BBCodes, removing [URL's
by ultranerds (Hermit) on Apr 23, 2009 at 14:17 UTC
    Thanks, will check that out :)

    Cheers

    Andy
        NM, managed to sort with:

        $test_string =~ s/lien/url/sig; # the parser doesn't seem to like this $test_string =~ s/\[url "(\?\%\:\/a-zA-Z0-9_\-\.+)"\]/url=$1/sig;

        Cheers

        Andy
Re^2: BBCodes, removing [URL's
by ultranerds (Hermit) on Apr 23, 2009 at 16:33 UTC
    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?
        Ok,managed to sort it.

        my $test_string = q| [lien "dfgdgdg"][img]sdfsdfsdf[/img][/url] [lien "dfgdgdg33"][img]sdfsdfsdf[/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]|; $test_string =~ s/lien/url/sig; # the parser doesn't seem to like +this $test_string =~ s/\[url "([\?\%\:\/a-zA-Z0-9_\-\.=]+)"\]/[url=$1]/ +sig; while ($test_string =~ m%\[url=([\?\%\:\/a-zA-Z0-9_\-\.=]+)\]\[img +\]([\?\%\:\/a-zA-Z0-9_\-\.=]+)\[/img\]%gix) { print "FOO: $1 , and $2 \n"; }
        Seems to work fine:
        FOO: dfgdgdg , and sdfsdfsdf FOO: dfgdgdg33 , and sdfsdfsdf FOO: http://www.smileycentral.com/?partner=ZSzeb001 , and http://smile +ys.smileycentral.com/cat/12/12_1_220.gif


        Seems to be working ok atm - will do some more tests though.

        Weird thing though, is if I change the regex to:
        while ($test_string =~ m%\[lien \"([\?\%\:\/a-zA-Z0-9_\-\.=]+)\"\] +\[img\]([\?\%\:\/a-zA-Z0-9_\-\.=]+)\[/img\]\[/lien\]%gix) { print "FOO: $1 , and $2 \n"; }

        ..and get rid of the stuff that converts [lien "link"] to [url=whatever] .. it doesn't seem to work (no matches)

        Cheers

        Andy
        UPDATE - never mind - sorted it:

        Thanks for the help guys.

        Cheers

        Andy