perl -e '$n = "Price 15.40"; $n =~s/[^\d.]//g; print "$n\n";'
Produces
15.40
--
seek $her, $from, $everywhere if exists $true{love};
| [reply] [d/l] [select] |
Oh, sorry. Now its working. Could you please explain what the expression ^\d. means? Would be nice to understand how it works.
What if I want this to work also for ","? In order words I would like it to extract all digits, "." AND ",". Is that possible?
Thanks!
| [reply] |
I you enclose bits of code in <c> and </c> tags the square brackets you typed will be preserved rather than being taken as some sort of link.
So, [\d.] denotes a character class consisting of digits and a full stop. Note that \d is in itself a character class which is the equivalent of [0-9]. Adding a comma is simplicity itself - [\d.,]. Have a look at perlretut and perlre for further information.
I hope this will be helpful.
Cheers, JohnGG
Update: As AnomalousMonk points out, I totally forgot to explain the significance of the caret symbol at the start of a character class. Sorry!
| [reply] [d/l] [select] |