tags:

views:

399

answers:

5

I have input text that contains a ' like in this text "Frank's Reel Movie Reviews"

how do I get rid of the '

I have tried

.replace (/\'/ig, '');
.replace ('\'', '');

But it seem like the ' does now want to be deleted...

I am thinking that the ' maybe encoded utf-8 or something

Any ideas

+1  A: 

Assuming you're working with Java, have you tried .replaceAll("'", "")? Works for me.

Brabster
I have tried it Brabster that is why I am thinking it is some sort of encoded ' cause I just don't get to kill it
Gerald Ferreira
The examples you gave had escaped the quote, which is why I suggested this. I guess I might start converting the string to hex and comparing it with some character code tables. Tricky without more context about where the string comes from
Brabster
A: 

If you just want to have letters and spaces in your result, you could always match any character that isn't one of those, such as...

.replace (/[^a-zA-Z ]+/ig, '');

You could of course also add any other characters you desired to permit to the regex.

Amber
+1  A: 

The regex [^\w ] will match anything that is not alphanumeric or space.

You could use this to ensure all apostrophes/quotes/etc get removed, even if done with Unicode - though there is not enough information in the question to know if this is acceptable.

Peter Boughton
I need some other special characters in the string like # , // etc... it is just the bugging ' that I need to kill
Gerald Ferreira
Then you can add the special characters to the class - e.g. `[^\w #/]` - but more importantly ***give more details in the question on what you're trying to do and what language this is!***
Peter Boughton
(/[^\w #\/,\?]/ig,"") hahahha - Thought it would be answered in minutes - THANKS A MILLION PETER - just learned something new!!!
Gerald Ferreira
No problem. I'd still recommend a proper parameterized query though - as well as safer it could be better performance.
Peter Boughton
' <<< I have now accessed that the apostrophy were actually encoded into ' - and use this (/\'/ig,"");
Gerald Ferreira
A: 

The ' should not need to be escaped. Try leaving it naked, without the backslash.

Cameron
var stripped31 = htstring31.replace("'",""); <<< I have tried it but the bugger sticks
Gerald Ferreira
A: 

Apostrophe is not a meta character.you should not escape it.

Allen it is either I escape the apostophre or I have no database, sometimes we need to do stuff to make what we want to work, even if it is not conventional...
Gerald Ferreira
Hi allen, sorry I now only see what you meant with it is not a meta character should not need to be escaped! - Thanks for the input
Gerald Ferreira