Search code examples
regexperlmatchperiod

Regular Expression Perl period quotation


After trying N+1 times with regex in Perl: I have the following problem: I need to retrieve this:

  232310..1.3      3213   2.4  "$250 For My jacket" (2012)

I am trying to retrieve it via:

if ( $line=~m/^\s+(\d+|\.+)\s+(\d+)\s+(\d+|\.+)\s+(\^"&(\w*|\s*|\D*)"$)\s*\((\d+)\s*/){
        $ID=$1;
        $Amount=$2;
        $Size=$3;
        $Item=$4;
        $Year=$5;

It does not work


Solution

  • (\d+|\.+) means either one or more digits or one or more periods. But what you want is ([\d.]+) which means one or more of digits or periods.

    Similar problem exits for capturing size and item as well. Also you're incorrectly using the start anchor (^) and the end anchor($).

    You can try:

    ^\s+([\d.]+)\s+(\d+)\s+([\d.]+)\s+"([^"]+)"\s*\((\d+)\s*
    

    See it