Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
03-01-2013, 06:38 PM #1
- Join Date
- Feb 2010
- Thanked 0 Times in 0 Posts
replace function escaped characters.
I am trying to remove single quotes and double quotes from a string of escaped characters,
it works with all except for single quotes ' and double quotes "
this is my code:
var newstrchanged = strEscaped.replace(/^%22/g, ' '); //does not remove the double quotes
var newstrchanged = strEscaped.replace(/^%27/g, ' '); //does not remove the single quote
var newstrchanged = strEscaped.replace(/^%3A/g, ' '); //does remove the SEMI COLON %3A
thank you for your help
03-01-2013, 07:12 PM #2
- Join Date
- Jun 2002
- London, England
- Thanked 2,536 Times in 2,514 Posts
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
03-01-2013, 07:28 PM #3
Not to ask a silly question, but...
Why not first *UNESCAPE* the text? Which is what, I think, Philip was assuming you would do. And then do the replacement on the unescaped text.
But anyway, your use of /^ means that it will ONLY find characters at the START of the text. That is, it will only replace the characters you are specifying if they are the first character in the string.
Equivalent of Philip's code, but using the escaped versions, instead.Code:var newstrchanged = strEscaped.replace(/\%(22|27|3A)/gi, ' ');
You may not need the \ in front of the % but it doesn't hurt to use it to be safe.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.