regex with comments

Run Settings
LanguageGo
Language Version
Run Command
package main import ( "fmt" "regexp" ) func main() { test_pattern := ` \b (?P<version> (?P<calver> v # "v" version prefix (?P<year>\d{4}) (?P<month>\d{2}) ) (?P<build> \. # "." build nr prefix \d{4,} ) (?P<release> \- # "-" release prefix (?:alpha|beta|dev|rc|post) )? )(?:\s|$) ` test_text := ` v201711.0001-alpha v201712.0027-beta v201801.0031 v201801.0032-post ... v202207.18133 v202207.18134 ` results := FindAll(test_pattern, test_text) for _, res := range results { // fmt.Printf("%#v\n", res) fmt.Printf("%s %s %s %s\n", res["year"], res["month"], res["build"], res["release"]) } } func CleanMultilineRegexPattern(pattern string) string { leading_whitespace_re := regexp.MustCompile("\n[ \t]+") trailing_whitespace_re := regexp.MustCompile("[ \t]+\n") comment_re := regexp.MustCompile("(^|\n|[ \t]{2,})#.*") cleaned_pattern := pattern cleaned_pattern = comment_re.ReplaceAllString(cleaned_pattern, "") cleaned_pattern = leading_whitespace_re.ReplaceAllString(cleaned_pattern, "") cleaned_pattern = trailing_whitespace_re.ReplaceAllString(cleaned_pattern, "") // fmt.Printf("%#v\n", cleaned_pattern) return cleaned_pattern } func FindAll(pattern string, haystack string) []map[string]string { cleaned_pattern := CleanMultilineRegexPattern(pattern) compiled_re := regexp.MustCompile(cleaned_pattern) re_names := compiled_re.SubexpNames() sub_matches := compiled_re.FindAllStringSubmatch(haystack, -1) result := make([]map[string]string, len(sub_matches)) for i, sub_match := range sub_matches { group_map := map[string]string{} for j, group_value := range sub_match { group_name := re_names[j] group_map[group_name] = group_value } result[i] = group_map } return result }
Editor Settings
Theme
Key bindings
Full width
Lines