Results 1 to 3 of 3
  1. #1

    Regex expert advise

    I need todo a complex search-n-replace and can't get the Regex for it. I've checked many Regex tutorials and also code libraries but can't figure it out.

    I need todo this in multiple files...replace a multi-line block of text that has common starting and end phrases, but variable text within. For ex. replace the following Multi-line text block...

    <b>Price List</b>

    ...some text here...varies with file....
    ...some text here...varies with file....
    ...some text here...varies with file....

    <u>email us for a custom quote</u>


    ....with this...


    <?php include("pricetable.php") ?>
    <?php include("footer.php") ?>


    Since the text within the delimiting phrases varies...so only a regular expression can help and not a normal text search. Quite a lot of files to process...any regex code idea for this ??

    The regex I made works for single line but not for multi-line text blocks.

  2. #2
    Join Date
    Mar 2001
    Posts
    1,434
    You could do it with a perl script to rewrite the file line by line, then when you hit the first delimiter, write your custom code, then write file again as normal when you hit end delimiter, then copy temp file over original. Not exactly a regex one liner, but would do the trick.

    - John C.

  3. #3
    Join Date
    Jun 2003
    Posts
    673
    Very lightly tested:
    Code:
    perl -ni -e 'if (m!<b>Price List</b>!) { while (<>) { last if (m!<u>email us for a custom quote</u>!); } print "<?php include(\"pricetable.php\") ?>\n<?php include(\"footer.php\") ?>\n"; } else { print $_; }' filenames

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •