- or download this
$_ = "I have 2 numbers: 53147";
if (/(.*?)(\d+)/)
...
#prints: Beginning is <I have >,number is <2>.
# Don't tell me that $1 = "I have ".
# Just execute the print statement and show the output.
- or download this
use warnings;
use strict;
...
}
#prints: Beginning is <I have >,number is <2>.
- or download this
my $string = "I have 2 numbers: 53147";
if ($string =~ /(.*)(\d+)/)
...
print "Beginning is <$1>,number is <$2>.\n";
}
#prints: Beginning is <I have 2 numbers: 5314>,number is <7>.
- or download this
my $string = "I have 325 numbers: 98765 12324";
if ($string =~ /(\d+)\D+(\d+)/)
...
print "Beginning is <$1>,number is <$2>.\n";
}
#prints: Beginning is <325>,number is <98765>.
- or download this
\d, a digit[0-9] \D a non digit
\w, a word character[a-zA-Z0-9_] \W a non word character
\s, a white space char [\s\t\f\r\n] \S a non-whitespace char