Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

Replacing text with matched text from same string

  •  08-15-2008, 1:32 AM

    Replacing text with matched text from same string

    Hello, I need help on matching and replacing text with different matched text from same string. My goal is to be able to batch process a large set of text files that each have similar patterns and replacement criteria. Below is an example of a typical case. In the example below, BOLD text replaces strikeout text:

    TITLE: Beautiful Losers - 8/22/2004 12:43:00 AM
    AUTHOR: mt San Francisco
    DATE: 8/22/2004 12:43:00 AM
    -----
    BODY:
    Yerba Buena Center for the Arts
    Through October 10, 2004

    Reviewed by Clark Buckner


    ....  text of varying length here ...


    <!-- BIO>Clark Buckner works as the gallery director at Mission 17 and writes the weekly "Critic's Choice: Art" column for the <i>San Francisco Bay Guardian</i>.*review by Clark Buckner~--><!-- MENU>Beautiful Losers by Clark Buckner~-->
    -----
    --------

    What I want to do is in the line:

    AUTHOR: mt, San Francisco

     replace


    mt, San Francisco

     with:

    Clark Buckner

    to get:

    AUTHOR: Clark Buckner

    Clark Buckner is matched from the bold instance in this section of code at the bottom:

    <!-- BIO>Clark Buckner works as the gallery director at Mission 17 and writes the weekly "Critic's Choice: Art" column for the <i>San Francisco Bay Guardian</i>.*review by Clark Buckner~--><!-- MENU>Beautiful Losers by Clark Buckner~-->


    the match I want to capture is always the first instance of text between "*" and the string "by ", and ending in the first "~"

    (I do not want to capture from the area beginning with <!-- MENU>)

    I've experimented on regex simulator tools and am just hitting a wall on how to form the expression. I'm working in an environment that supports standard perl regex. Any help would be very much appreciated. Many thanks.

View Complete Thread