Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a $cbDescription variable in a Perl script. When I print out $cbDescription, I get the following:

tIP SOLD -5 /ESH4 @1832.00

I want to remove any + or - or @ signs or commas from the string, so I have the following line:

$cbDescription =~ s/[+-\@,]//g;

I expect that line to change $cbDescription to:

tIP SOLD 5 /ESH4 1832.00

But when I print out $cbDescription after that line, I get:

tIP SOLD  ESH

Why did it also remove all the numbers and the decimal point?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

- is a range delimiter in between brackets sou you need to escape it:

% echo "tIP SOLD -5 /ESH4 @1832.00" | perl -pi -e 's/[+\-\@,]//g'
tIP SOLD 5 /ESH4 1832.00
share|improve this answer
2  
You can also specify it as the very first character in the class. –  choroba Feb 16 at 23:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.