regex to remove 1 character from string conditional

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, '');

LVL 1
TARJrAsked:
Who is Participating?
 
Marco GasiConnect With a Mentor FreelancerCommented:
Try this

$result = preg_replace('/\$(?=[a-zA-Z]+)/', '', $subject);
0
 
leakim971PluritechnicianCommented:
what don't you want from this one?
http://jsfiddle.net/ddsC9/2/
0
 
TARJrAuthor Commented:
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
 
Kiran SonawaneConnect With a Mentor Project LeadCommented:
try this
$result = preg_replace('/\$(?=[a-zA-Z]+)/g', '', $subject);
0
 
TARJrAuthor Commented:
bingo, I forgot the Global flag. /g
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.