Solved

regex to remove 1 character from string conditional

Posted on 2011-09-30
5
175 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 125 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 125 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

631 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