in reply to Regular Expression Elegance

This seems to be hunky-dorie but I’m sure that there a single line regular expression solution, don’t you?
I've been here long enough to know that the proper answer to "What regex allows me to manipulate this markup language in the way I want?" is "Don't use regexes to manipulate markup; use dedicated parsers", and yet I see that far wiser monks than I have given different answers. On reflection, that's probably because your $value is like no HTML on earth. Where is this coming from? (It's irrelevant to the solution, but I'm curious.)

Replies are listed 'Best First'.
Re^2: Regular Expression Elegance
by monkie (Novice) on Nov 11, 2008 at 16:23 UTC
    you're opening a can of worms here . . . legacy code is the short answer!

    user input is saved from a multi-line textbox to a db. To display the text, carrige returns are handled by this:
    $value =~ s/\n/<br>/g;
    recently code has been added to allow hyperlinks to be inputed by users, using custom tags handled by another reg expresion. If a typed link is longer than the multi-line textbox width, it will wrap and thanks to the above reg expresion will contain a <b> which breaks the link.
    now you know . . .
      I guess that it's not possible to get at the $value before the <br>-substitution—maybe making a copy of it, so that you don't stomp on the display manipulations—and perform the substitution $value =~ s/\n//g on it instead?
        yes I can but then I would still need to remove the newline chars from within the my tags but then at least it would never contain the <b> tags.