Jon Weinraub
Jon Weinraub

Reputation: 394

Strip all non numbers but decimal in a delimited data set in PERL

I have a data set that has a delimiter and I like to remove all non numerical data but keep the decimal point if it has one.

I can't figure out how to include the decimal itself since right now it strips it with this:

$output =~ s/[^0-9|\|]*//gi;

A sample of the output is: 38.1mm|1013.88s|81%|22°

So I want to see: 38.1|1013.88|81|22

Thanks

Upvotes: 0

Views: 557

Answers (2)

toolic
toolic

Reputation: 62164

The transliterate operator tr/// can delete characters:

$output =~ tr/0-9.|//cd;

Upvotes: 4

p.s.w.g
p.s.w.g

Reputation: 149050

Try this:

$output =~ s/[^\d.|]+//g;

This will remove any characters other than digits, ., or |.

Upvotes: 1

Related Questions