PDA

View Full Version : Javascript RexExp


Mr.Shum
10-26-2004, 12:13 AM
Hi there,

I'm new on javascript regexp and wonder if anyone can help me. I like to replace all quote to " but not the quote inside a html tag.

Example:
StringToReplace = 'Joy say "Hello" to <Font color="red">you</Font> and say "hi" to me'

ReplacedString = 'Joy say &quot;Hello&quot; to <Font color="red">you</Font> and say &quot;hi&quot; to me'

Thanks in adv.

Philip M
10-26-2004, 08:06 AM
Try this (easier to change all quotes to &quot; and then
change required ones back)

ReplacedString = StringToReplace.replace(/"/g, "&quot;");
ReplacedString = ReplacedString.replace(/=&quot;/g, """);
ReplacedString = ReplacedString.replace (/&quot;>/g, """);

Do please avoid the gruesome expression "Thanks in adv". It is
discourteous.

adios
10-26-2004, 07:41 PM
var RE = /"(?![^<>]*>)/g;

StringToReplace = 'Joy say "Hello" to <Font color="red">you</Font> and say "hi" to me';

alert(StringToReplace.replace(RE, '&quot;'));