re = /(?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\:])/m
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)
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html