Click to See Complete Forum and Search --> : Efficient Search and Replace on Multiple Conditions


askohen
01-08-2007, 11:45 AM
Hi. As an exercise for a beginner at JS, I would like to do the following: Convert a string of HTML to escaped HTML, with entities instead of brackets etc. My thinking is this:

1) Using reg expressions create a pattern that matches '<', '>', '&' BUT NOT any word beginning with '&' ';' and ending with ';'. --so that actual entities are not (re)converted to entities...

2) Use regex.exec(), get an array of all matches

3) Replace those matches with corresponding HTML entities.

4) Return the replacements back into the string.

I can loop through the matches using a while loop with re.exec(), and reassign each n element of the array with the entity, but I have no idea how to then return that back into the string. Am I on the right track, or is there an easier way? Thanks.

askohen
01-09-2007, 07:52 AM
Anyone have any ideas on this? I just want some direction and want to know if I am on the right path, or if there is an easier or better way to do this. Thanks in advance.