What does "$line =~ /\-?(?:\d+\.?\d*|\.\d+)/g mean in perl?


Could someone please explain to me character by character?

1 Answer

  • Alan
    Lv 7
    6 months ago

    I don't understand the ? and they could change the meaning of other expression

    (like tell you to ignore them )

    simpliest items

    d means digits (0-9)

    + means 1 or more of the item before it

    * means 0 or more of the item before it.

    . means any characters

    | means or


    /g (means globally) (check again and again )

    it means

    if variable $line contains

    now bit by bit

    /- means escape sequence -

    means contains a - (I think)

    I don't understand all the ? and the

    ":" (it may be part of ? expression.

    \d+ means one or more digits (0-9)

    \. means any character

    \d* means zero or more digits (0-9)

    2nd opinion

    from this site


    It evaluates this part


    as seen in the image below, You put it in your self to try again.

    Attachment image
    • Alan
      Lv 7
      6 months agoReport

      Usually you return things between parenthesis as a variable
      maybe as $1 , $2

    • Login to reply the answers
Still have questions? Get your answers by asking now.