Solved

How to replace with single quote ?

Posted on 2011-03-17
5
516 Views
Last Modified: 2012-05-11
The following expression replace a
forward slash with two single quotes

i want only to one single quote


item_name.replace(/\\/g,"\'");
0
Comment
Question by:PeteEngineer
[X]
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
  • Learn & ask questions
5 Comments
 
LVL 3

Accepted Solution

by:
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

by:sjklein42
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'
alert(item_name)
item_name = item_name.replace(/\\/g,"\'");
alert(item_name)
</script>

Open in new window

0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
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,"\'");

Open in new window

0
 
LVL 3

Assisted Solution

by:grouper15
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

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

Open in new window

0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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)

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question