in reply to What's wrong with this regex
(?i-msx:(?:(\d+)\.)+(\d+)) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?i-msx: group, but do not capture (case-insensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- (?: group, but do not capture (1 or more times (matching the most amount possible)): ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- \d+ digits (0-9) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- \. '.' ---------------------------------------------------------------------- )+ end of grouping ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- \d+ digits (0-9) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
Here is one way to get what you want:
use warnings; use strict; $_ = "1.2.17.3 Glückwunschschreiben 12 und"; if ( /(\d+)\.(\d+)\.(\d+)\.(\d+)/ ) { print "$1 $2 $3 $4\n"; } __END__ 1 2 17 3
|
|---|