8

i'm having a problem replacing ==> (apostrophe) with a space i know it looks so easy but what i mean is editors don't type apostrophe like this ==> but like this ==> ' and i can't find a way to replace it using

var newtext = old.replace(/'/g,"");

here's an example http://jsfiddle.net/zYK9f/4/ in this example you can type ==> in the page but not in the code editor tried a lot but no result hope you can help thanks sorry i mean apostrophe not semicolon

10
  • 6
    That looks like an apostrophe to me... Commented Feb 13, 2012 at 19:51
  • What kind of "editors" are you referring to and why is that a problem? Commented Feb 13, 2012 at 19:56
  • I think I've encountered something similar in the past...he may be referring to text that's copied from Microsoft Word that contains either an apostrophe or a quote. MS Word annoyingly replaces these symbols with something fancier, which may not be interpreted well when pasted into other text editors. Commented Feb 13, 2012 at 19:59
  • Just FYI (and WolframAlpha backs me up on this): the former character is a right-single-quote, and the latter is an apostrophe. Different things. Commented Feb 13, 2012 at 20:00
  • 1
    @MattiVirkkunen: Sure, but does your keyboard have both characters? Mine certainly doesn't. Commented Feb 13, 2012 at 20:24

3 Answers 3

7

Just copy and paste the character to account for both:

var newtext = old.replace(/'|’/g,"");
Sign up to request clarification or add additional context in comments.

Comments

5

I'm not sure what you are asking for... like the other answers suggested, you can use

var newtext = old.replace(/'|’/g," ");

However, if the character isn't allowed in your editor, you can use the unicode equivalent:

var newtext = old.replace(/\u2019/g," ");

2 Comments

+1 for mentioning Unicode literals. However, the OP wants to substitute quotation marks with a space, not an empty string; also, the second alternative you propose contains a syntax error (missing a comma between the two arguments of replace) and is not equivalent to the first (missing ' in the regular expression).
i'm using dreamweaver thanks all i used /\u2019/ instead of /'/ and now it's working thanks all
1
var old = "you’ll keep’’’ finding more and ''''more ways to use it.";
var newtext = old.replace(/’/g,"");
var newtext = newtext.replace(/'/g,"");
$("#text").html(newtext);

Will get rid of both types of apostrophes. Is this what you want?

2 Comments

the problem is dreamweaver can't deal with ’ just ' i don't know if it's blind
try using "’". That's the HTML code for the curly apostrophe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.