Replace list of words with associated links

View: New views
1 Messages — Rating Filter:   Alert me  

Replace list of words with associated links

by danthemightyone :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a list of words and corresponding links eg.

dog www.bigdog.com

cat www.nicecat.com

fox www.fox.com

Can I have one regular expression that will replace all the words on the left hand side of the list (ie. dog, cat, fox) with the left hand side (www.bigdog.com, www.nicecat.com, www.fox.com)?

Lets take an input string:

The dog saw the cat and fox laughing.

I want the output to be:

The dog saw the cat and fox laughing.

I will take the word/link list as xml eg;

<masterlist>
   <keyword>
      <text>dog</text>
      <url>http://www.bigdog.com</url>
   </keyword>
   <keyword>
      <text>cat</text>
      <url>http://www.nicecat.com</url>
   </keyword>
   <keyword>
      <text>fox</text>
      <url>http://www.fox.com</url>
   </keyword>
</masterlist>

I am also using msxsl c# script for the reular expression.
At the moment I am using a recursive function to replace the the contents of text node with url node. However the problem is that the longer the list gets the longer it takes for all the text to get replaced. I would really like to have an expression that will replace a group of text with a group of urls, in one go.

Can this be done?
LightInTheBox - Buy quality products at wholesale price!