Pragma: UseUnicode
Pragma: UseUtils

BeginProgram: RegEx1

BeginMain:
	ScalarDecl: final <string> s = "Four score and seven years ago..."
	PrintLine: "Match 1: ", match(s, qr/s.*e/)
	PrintLine: "Match 2: ", match(s, qr/\bs.*e\b/)
	PrintLine: "Match 3: ", match(s, qr/s...e/)
	PrintLine: "Match 4: ", match(s, qr/b.d/)
	
BeginEval: language =~ qr/pl/
# Perl doesn't capture the whole match as the first subgroup unless you add extra ()
	ListDecl: [<string>] subgroups = findFirst(s, qr/((\w+)\s*(\w+))/)
ElseEval
	ListDecl: [<string>] subgroups = findFirst(s, qr/(\w+)\s*(\w+)/)
EndEval
	PrintLine: "Find First (with subgroups): ", listToString(subgroups)
	Assign: subgroups = findFirst(s, qr/bad match/)
	PrintLine: "Find First (bad match): ", listToString(subgroups)
	
	ListDecl: [<string>] matches = findAll(s, qr/\w+/g)
	PrintLine: "Find All: (matches only)", listToString(matches)
	Assign: matches = findAll(s, qr/bad match/g)
	PrintLine: "Find All (bad match): ", listToString(matches)
EndMain
EndProgram
