package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)(?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\:])`)
var 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)
`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
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 Golang, please visit: https://golang.org/pkg/regexp/