in reply to substituting capture groups substrings

$line =~ s/(/d/d)(/d/d)/$1 $2/g

Replies are listed 'Best First'.
Re^2: substituting capture groups substrings
by MidLifeXis (Monsignor) on Jul 14, 2015 at 13:19 UTC

    For future browsers: /d should be \d, and really, unless you intend to allow unicode digits, should probably be [0-9].

    --MidLifeXis

       For future browsers: /d should be \d, and really, unless you intend to allow unicode digits, should probably be [0-9].

      Thats what //a and //aa are for (since v5.13.10 according to perlver)

      $ perl -Mre=debug -le "print qr/\d/" Compiling REx "\d" Final program: 1: DIGIT (2) 2: END (0) stclass DIGIT minlen 1 (?^:\d) Freeing REx: "\d" $ perl -Mre=debug -le "print qr/\d/u" Compiling REx "\d" Final program: 1: DIGIT (2) 2: END (0) stclass DIGIT minlen 1 (?^u:\d) Freeing REx: "\d" $ perl -Mre=debug -le "print qr/\d/a" Compiling REx "\d" Final program: 1: DIGITA (2) 2: END (0) stclass DIGITA minlen 1 (?^a:\d) Freeing REx: "\d" $ perl -Mre=debug -le "print qr/\d/aa" Compiling REx "\d" Final program: 1: DIGITA (2) 2: END (0) stclass DIGITA minlen 1 (?^aa:\d) Freeing REx: "\d"

        Only if you have the capability to run on perls newer than that. [0-9] works back much further.

        --MidLifeXis