Search & Replace in HTML String

Results 1 to 2 of 2

Thread: Search & Replace in HTML String

  1. #1
    Join Date
    Dec 1969

    Default Search & Replace in HTML String

    Hi All,<BR><BR> I am trying to find a solution for many days in many list.<BR> <BR> I am reading and .HTM file as text stream using File System.<BR> Now I want to search for a particular word in this string and replace with some other word.<BR> <BR> I want to make it sure that this will not replace that particular word in META tags, Links, Image Tags etc. I just want to replace in pure text.<BR> <BR> How can I do that.? I think the regular expression is the best choice. I did not work in Reg Exp at all.<BR> <BR> Please give me any kind of help in Code, reference and links related to the particular problem.<BR> <BR> Examples in VBScript/ASP is requested.<BR> <BR> Thanks for all,<BR> <BR> Abbas<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Search & Replace in HTML String

    Say you want to replace the word "cold" with "hot"<BR><BR>Use this pattern: <BR><BR>(&#062;[^&#060;]*)(cold)<BR><BR>For example: <BR><BR>Set re = New RegExp <BR>re.Global = true <BR>re.IgnoreCase = true <BR>re.Pattern = "(&#062;[^&#060;]*)(cold)"<BR>myText = re.Replace(myText,"$1hot")<BR><BR>The pattern looks for a right bracket (&#062;), followed by anything but a left bracket (&#062;) followed by the letter sequence "c", "o", "l", then "d"<BR><BR>So, $1 is from "&#062;" right up to just before the "c" in "cold", and $2 is "cold". So, in the replace method, we put the $1 back in, but discard $2 and instead use "hot".<BR><BR>The parenthesis determine what&#039;s $1, $2, ... Count opening parenthesis from the left.<BR><BR>You can play with the regex pattern at<BR><BR>Hope that makes sense...

Posting Permissions

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