in reply to Re^3: extracting number from string
in thread extracting number from string

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!

Replies are listed 'Best First'.
Re^5: extracting number from string
by johngg (Canon) on Mar 05, 2009 at 14:03 UTC

    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!

      And further, the regex metacharacter  ^ at the beginning of a character set complements the characters specified in the set, so that  [^\d.,] means "any character except a decimal digit, full-stop or comma".