in reply to extracting number from string

=~ s/[^\d.]//g; or you can borrow regex from How do I determine whether a scalar is a number/whole/integer/float?

Replies are listed 'Best First'.
Re^2: extracting number from string
by samuelalfred (Sexton) on Mar 05, 2009 at 10:33 UTC
    Thank you, but this doesn't quite do what I want. If $number = "Price 15.40", the result from

    $number=~s/^\D.//g

    is

    $number = ice 15.40

    Any idea how to get this to be just 15.40?

    Thanks!

      You copied the regex incorrectly.

      perl -e '$n = "Price 15.40"; $n =~s/[^\d.]//g; print "$n\n";'
      Produces
      15.40
      --
      seek $her, $from, $everywhere if exists $true{love};
        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!