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

Find and Replace using RegEx in Dreamweaver MX 2004 to Replace/Copy Specific Attributes

Last post 11-23-2009, 11:58 AM by ddrudik. 6 replies.
Sort Posts: Previous Next
  •  11-18-2009, 1:52 PM 57395

    Find and Replace using RegEx in Dreamweaver MX 2004 to Replace/Copy Specific Attributes

    Hi there,

    I'm currently working on remodeling an antiquated site, using Dreamweaver (MX 2004, unfortunately :-p). Part of the process involves adding page-based navigation (i.e. previous, next, home, etc.) at the top of each page, where originally it was only at the bottom.

    Using my limited knowledge of Regular Expressions, I've already managed to update the code/styling for the existing navigation at the bottom (e.g. using Dreamweaver's Find and Replace with Regular Expressions to locate the tags in questions—anchor tags, for instance—and preserve the attribute data, while modifying class names, adding divs, etc.) and I even batch-added the structure for the navigation at the appropriate place at the top of the page. What I'd like to do now, is to copy the attribute information from the links at the bottom of the page (hrefs and whatnot) into the corresponding attributes in the navigation at the top of the page.

    Here's an example of the code I'm working with:

    <div class="pageNav-top">

    <ul>

    <li class="previous-top"><a href="http://regexadvice.com/forums/AddPost.aspx?ForumID=68#">Previous</a></li>

    <li class="home-top"><a href="../../index.html">Home</a></li>

    <li class="needToKnow-top"><a href="needtoknow.html">What I Need to Know</a></li>

    <li class="maps-top"><a href="../../maps/index.html">Maps</a></li>

    <li class="next-top"><a href="http://regexadvice.com/forums/AddPost.aspx?ForumID=68#">Next Page</a></li>

    </ul>

    </div>

    <div id="textBody">

    <div class="inTextImage iFloatRight">
          <span>Watch the Video</span>
          <a class="flowplayer" href="../../hst111/10_civil-war/videos/Fort_Sumter_VP6_384K.flv"><img src="images/videostill-fort-sumter.jpg" alt="Fort Sumter" width="329" height="224" /></a>
          <span>Video Length= 4:20</span>
     </div><!-- end of inTextImage iFloatRight -->

    <h3>Fort Sumter</h3>

    <p>Having declared separate status from the Union, South Carolina (and other states) waited to see what response the Union would make. Lincoln forced the South to fire the first shot by announcing his intention to resupply a federal fort in Charleston harbor. If South Carolina allowed the resupply, the rebellion would be effectively ended. The Fort was bombarded heavily by shore emplacements before the Union resupply ships could arrive. Surrender followed in turn and the Civil War was officially underway. </p>

    </div><!-- end of textBody -->

    <div class="pageNav-bottom">

    <ul>

    <li class="previous-bottom"><a href="election-1860.html">Previous</a></li>

    <li class="home-bottom"><a href="../../index.html">Home</a></li>

    <li class="needToKnow-bottom"><a href="needtoknow.html">What I Need to Know</a></li>

    <li class="maps-bottom"><a href="../../maps/index.html">Maps</a></li>

    <li class="next-bottom"><a href="early-war.html">Next Page</a></li>

    </ul>

    </div>

    So what I want to do is copy the href attribute values from the "Previous" and "Next" links at the bottom of the page (inside the pageNav-bottom div), into the (currently blank, href="[poundsign]") corresponding "Previous" and "Next" href attributes in the navigation at the top of the page (inside the pageNav-top div), while ignoring any content (tags, text, or otherwise) in-between.

    It seems like with RegEx's there should be a way to do this, but I'm not quite sure how. I know that I can find and grab the attribute values using something like this href="([^"]*)", and then reference them with $1, $2, etc., but I'm not sure how to only deal with the sections of the page that have the top and bottom navigation, while ignoring everything else.

    Any help would be greatly appreciated!

  •  11-18-2009, 2:19 PM 57397 in reply to 57395

    Re: Find and Replace using RegEx in Dreamweaver MX 2004 to Replace/Copy Specific Attributes

    Sounds like a limitation of MX and not regex *hint hint*

     

    You could make some bloated regex but your not going to save anytime, double-click, ctrl-c double-click, ctrl-v are your friends

  •  11-18-2009, 3:02 PM 57398 in reply to 57397

    Re: Find and Replace using RegEx in Dreamweaver MX 2004 to Replace/Copy Specific Attributes

    I'm afraid that may be the solution, but it still seems like there would be a more elegant RegEx solution.  I'll admit, I'm not overly familiar with RegEx, so I guess I could be overstating its capabilities, it just seems like it should be possible.  In essence, all I really need to figure out at this point, is an Expression that basically says "ignore all content (HTML, text, etc.) from here until you reach <div class="pageNav-bottom">".  If I could figure that out, I think I'd be able to do it.
  •  11-18-2009, 3:13 PM 57399 in reply to 57398

    Re: Find and Replace using RegEx in Dreamweaver MX 2004 to Replace/Copy Specific Attributes

    It's not a limitation with regex, it's not using a scripting/programming language.

    I'm not sure if MX allows regex in the replace side, what you would need to do is have a regex to match the data at the top in the find and in the replace block have a regex that matches the bottom, you can use a lookahead or around to match the div----up to before the data you want.

     

    I'm thinking you'll still need to click find several times to get it to work... you're better off writing code to parse the document actually.

     

  •  11-18-2009, 4:27 PM 57400 in reply to 57399

    Re: Find and Replace using RegEx in Dreamweaver MX 2004 to Replace/Copy Specific Attributes

    Any suggestions as to how to do that would be sincerely appreciated, as the site contains well over 200 pages—making any automation a great help. 

    I'm fairly sure that Dreamweaver MX does allow for regex in the Replace field (though all I've used so far are the "$1" for recalling stored values) but I'd be more than willing to use another program to parse the documents, if that would be the simpler solution.  Again, as my alternative is the copy and paste method across hundreds of pages, I'd be very glad for anything that helps to automate the process.

  •  11-19-2009, 7:29 AM 57414 in reply to 57400

    Re: Find and Replace using RegEx in Dreamweaver MX 2004 to Replace/Copy Specific Attributes

    I would write you up a cheesy php script real quick but I'm working on a big project atm, could probably goolge for one.

     If your class names remain constatnt you can key off of them with:

     

    (?="previous-bottom"><a href=")([a-z0-9_\.-]+)"                                   --replace

    (?="previous-top"><a href=")([a-z0-9_\.-]+)"                                        --find

     

    We'll see when I get my project done.

     

  •  11-23-2009, 11:58 AM 57465 in reply to 57395

    Re: Find and Replace using RegEx in Dreamweaver MX 2004 to Replace/Copy Specific Attributes

    I don't follow what you want to replace with what, can you highlight that in your example?
View as RSS news feed in XML