SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Need Regex Help

  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need Regex Help

    I'm using Dreamweaver's search-and-replace function to convert a website that includes hundreds of pages with links to pages focusing on the world's nations.

    Consider the following links:

    [CODE]
    <td><a href="http://www.geoworld.org/sp" title="">Spain</a></td>
    <td><a href="http://www.geoworld.org/zi" title="">Zimbabwe</a></td>
    [CODE]

    Notice that they're exactly the same except for the two characters following the domain name (sp and zi) and the names visitors see (Spain and Zimbabwe). I want to replace the two characters with the country's name, and I also want to insert the country's name in the title attribute, so the finished URL's will look like this:

    [CODE]
    <td><a href="http://www.geoworld.org/Spain" title="Spain">Spain</a></td>
    <td><a href="http://www.geoworld.org/Zimbabwe" title="Zimbabwe">Zimbabwe</a></td>
    [CODE]

    Does anyone know how to make a regex script like that?

    One more detail...can you adjust it so that spaces in place names that consist of more than one word are replaced by underscores in the link, as follows? (If not, don't worry about it. I can probably fix that with a second regex that simply replaces spaces with underscores in links.)

    [CODE]
    <td><a href="http://www.geoworld.org/United_Kingdom" title="United Kingdom">United Kingdom</a></td>
    [CODE]

    And if my original request is too difficult, I'd settle for a regex that converts this...

    [CODE]
    <td><a href="http://www.geoworld.org/sp" title="">Spain</a></td>
    [CODE]

    to this...

    [CODE]
    <td><a href="http://www.geoworld.org/sp" title="">Spain</a>Spain2Spain3</td>
    [CODE]

    ...or something similar. If I could merely replicate the place name, with different characters after each occurrence, then I could fill in the blanks with a series of search and replace operations.

    Thanks!

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please don't post the same question several times. And don't post questions about regular expressions in the HTML/XHTML forum, since there are no regular expressions in those markup languages.
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

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