in reply to Re: guestbook font [colors]
in thread guestbook font [colors]

How would this work on colors embedded in each other like in my original example? Would this work?

I don't quite understand the magic in this regex.

Thank you!

Replies are listed 'Best First'.
Re^3: guestbook font [colors]
by GrandFather (Saint) on Aug 09, 2006 at 04:21 UTC

    To get a better answer provide a better example. What does your original text look like and what do you want the new version to look like? I answered my best guess at what you might have. I can't imagine what you might expect something like:

    This is a [color][color]test[/color][/color]

    to be rendered as. There is not enough information in that to indicate how color should be replaced in each case.

    You should visit the Tutorials section, in particular Strings and Pattern Matching, Regular Expressions, and Parsing.


    DWIM is Perl's answer to Gödel
      Okay, in my real code I have a database filled with color codes that are available. All codes have the same open and close tag, with the close having /.

      I'm iterating over my messages in a foreach() loop and splitting the messages up into individual data chunks (data, name, url, and message).

      From here, I want to filter the message for color codes (which I'd probably push into an array.

      my @array = qw(red blue orange); $message =~ s///; # subs all occurences of [red]test[/red] or [blue] w +oot! [/blue].

      A real world look at what the message might be:

      How [red]much would[red] could a wood [blue]huck chuck[blue]. If a [re +d]wood chuch could chuck[/red] wood? All the wood that peter pan is m +ade of.

      The output is pretty self explanatory which would be the real font color="red", color="blue" tags.

      Code tags added by GrandFather

        So you are suggesting that you are translating markup from a [stuff] form to HTML? If so, why didn't you say that in the first place and give some examples of the original text including nasty cases and a sample of the output text that you would like to be generated. If that is not what you are trying to do then I have no idea and you should give a before and after sample to clarify the problem.


        DWIM is Perl's answer to Gödel