http://qs321.pair.com?node_id=557280


in reply to Re^2: Regex to replace a particular part of content
in thread Regex to replace a particular part of content

Now do it when you don't know what the text is up front and the text varies from line to line.

With this version you might as well just have used a print statement containing the litteral output. I'm sure in OP's real problem the text is not as shown. A better sample may have comprised words like "foo bar baz" and been much shorter, but there were enough lines there that you should probably have been able to read between them. :).


DWIM is Perl's answer to Gödel
  • Comment on Re^3: Regex to replace a particular part of content

Replies are listed 'Best First'.
Re^4: Regex to replace a particular part of content
by johngg (Canon) on Jun 23, 2006 at 18:57 UTC
    If it was a real world problem with real HTML/XML/whatever you would recommend some sort of parser rather than regular expressions. However, the OP asked for a regular expression (misguidedly) to modify a piece of unrealistic text (I can read between the lines as well as the next man, who's ever seen real world mark-up like that?:-). I've had some fun and learnt a few things trying to see if it could be done that way so I'm happy.

    Cheers,

    JohnGG