• Status: Solved
• Priority: Medium
• Security: Public
• Views: 522

# How to replace with single quote ?

The following expression replace a
forward slash with two single quotes

i want only to one single quote

item_name.replace(/\\/g,"\'");
0
PeteEngineer
5 Solutions

Commented:
Instead of \' see if specifying the single-quote's hexadecimal reference works, which would be \0x27, or the octal reference \047.
0

Commented:
Your code seems to work fine:

(The code actually replaces backslashes \ , not forward slashes / .  Is that what you meant to say?)

<script>
var item_name = 'abc\\def'
item_name = item_name.replace(/\\/g,"\'");
</script>

0

Commented:
Perhaps you mean you want to replace a series of one-or-more slashes with just one single quote?
item_name.replace(/\\+/g,"\'");

0

Commented:
can you send the value of item_name you are having problem with
0

PluritechnicianCommented:
No need to escape the simple quote inside the double quote
item_name.replace(/\\/g,"'");

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.