use strict;
my $str = ' ! U+0021 EXCLAMATION MARK
" U+0022 QUOTATION MARK
# U+0023 NUMBER SIGN
$ U+0024 DOLLAR SIGN
% U+0025 PERCENT SIGN
& U+0026 AMPERSAND
\' U+0027 APOSTROPHE
( U+0028 LEFT PARENTHESIS
) U+0029 RIGHT PARENTHESIS
* U+002A ASTERISK
+ U+002B PLUS SIGN
, U+002C COMMA
- U+002D HYPHEN-MINUS
. U+002E FULL STOP
/ U+002F SOLIDUS
: U+003A COLON
; U+003B SEMICOLON
< U+003C LESS-THAN SIGN
= U+003D EQUALS SIGN
> U+003E GREATER-THAN SIGN
? U+003F QUESTION MARK
@ U+0040 COMMERCIAL AT
[ U+005B LEFT SQUARE BRACKET
\\ U+005C REVERSE SOLIDUS
] U+005D RIGHT SQUARE BRACKET
^ U+005E CIRCUMFLEX ACCENT
_ U+005F LOW LINE
` U+0060 GRAVE ACCENT
{ U+007B LEFT CURLY BRACKET
| U+007C VERTICAL LINE
} U+007D RIGHT CURLY BRACKET
~ U+007E TILDE';
my $regex = qr/[!-\/:-@[-`{-~]/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html