Web Analytics Made Easy -
StatCounter Simple regexp - replacing character codes - CodingForum

Announcement

Collapse
No announcement yet.

Simple regexp - replacing character codes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple regexp - replacing character codes

    I want a function that will take a HTML string, and replace all instances of "&" with "&" - unless, of course, the "&" is already suffixed by "amp;"

    Code:
    function cleanCharCodes(sString)
    	dim oRegEx, oMatches, oMatch
    	set oRegEx = New RegExp
    	oRegEx.Global = True 
    	oRegEx.IgnoreCase = False
    	oRegEx.Pattern = "&^(amp;)"
    	set oMatches = oRegEx.Execute(sString)
    	For Each oMatch in oMatches
    		sString = replace(sString, oMatch.value, "&")
    	Next
    	cleanCharCodes = sString
    end function
    It doesn't do anything. I assume my regexp is fubar'd but I dunno how? Help

  • #2
    Is this it:

    &[^(amp)]

    ??

    Comment


    • #3
      No, that's not it That matches the following char, too.

      I'm befuddled. Bemused. Stuck, shafted and possibly without a paddle.

      How do I do this? Every time I think I've got it, I find out that I'm replacing stuff twice, or something.

      Someone must have done something like this before?

      Comment

      Working...
      X