## Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

• Help others & share knowledge
• Earn cash & points
Solved

# How to replace with single quote ?

Posted on 2011-03-17
508 Views
The following expression replace a
forward slash with two single quotes

i want only to one single quote

item_name.replace(/\\/g,"\'");
0
Question by:PeteEngineer

LVL 3

Accepted Solution

CombatGold1 earned 100 total points
ID: 35155409
Instead of \' see if specifying the single-quote's hexadecimal reference works, which would be \0x27, or the octal reference \047.
0

LVL 16

Assisted Solution

sjklein42 earned 100 total points
ID: 35155473
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

LVL 75

Assisted Solution

käµfm³d   👽 earned 100 total points
ID: 35155527
Perhaps you mean you want to replace a series of one-or-more slashes with just one single quote?
item_name.replace(/\\+/g,"\'");

0

LVL 3

Assisted Solution

grouper15 earned 100 total points
ID: 35155715
can you send the value of item_name you are having problem with
0

LVL 82

Assisted Solution

leakim971 earned 100 total points
ID: 35155810
No need to escape the simple quote inside the double quote
item_name.replace(/\\/g,"'");

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)