use strict;
my $str = 'CC := nasm
BOOT_REQ := text.o
FREELDR_SRCS := freeldr.c
IMG_NAME := boot.img
TEXT_SECTION := 7c00
# UFS2, ZFS and/or RAW
FILESYSTEMS :=
CPU_FLAGS := PAE
SDK_FLAGS :=
VERSION := "1.00.00"
%.o:
$(ASM) ${SDK_FLAGS} -f bin -o $@ $(patsubst %.bin,%.asm,$@))
${IMG_NAME}:
$(BOOT_REQ) $(FREELDR_SRCS:.c=.o)
';
my $regex = qr/(?P<assign_op>(\:|\!|\?)?=)|(?P<token_subst>$|%(\<\@))|(?P<token_ident>[\w\d\.\,]+)|(?P<target_name_match>%\.?)|(?P<token_rule_sep>[:])|(?P<incr_op>\n)|(?P<line_end>\n)|(?P<comment_op>#[.*]+$)|(?P<adjust_parser>[\$%\s\t\:])/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