Solved

regex to remove 1 character from string conditional

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
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)

809 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