Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

regex to remove 1 character from string conditional

Posted on 2011-09-30
5
Medium Priority
?
176 Views
Last Modified: 2012-08-13
given the string:
"the value is $14 and not $dollar"

I want to remove the $ from the $dollar (characters) not the $14 (numbers).
should look like this:
"the value is $14 and not dollar"

I have this, but it removes the first letter next to the $dollar:

replace(/\$[^0-9]/g, '');

0
Comment
Question by:TARJr
[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 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 36892017
Try this

$result = preg_replace('/\$(?=[a-zA-Z]+)/', '', $subject);
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36892027
what don't you want from this one?
http://jsfiddle.net/ddsC9/2/
0
 
LVL 1

Author Comment

by:TARJr
ID: 36892353
margusG, that is almost perfect, but it only removes one occurrence of the $word.

if given: "the value is $14 and not $dollar but can be $this"

results: "the value is $14 and not dollar but can be $this"

0
 
LVL 17

Assisted Solution

by:sonawanekiran
sonawanekiran earned 500 total points
ID: 36892384
try this
$result = preg_replace('/\$(?=[a-zA-Z]+)/g', '', $subject);
0
 
LVL 1

Author Closing Comment

by:TARJr
ID: 36892405
bingo, I forgot the Global flag. /g
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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 code hide show and toggles. 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…

705 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