package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`\d{2}\w-\d{5}_(?P<code>DC\d{1,3})_(?P<well_adress>\w\d{2})_(?P<id>\d*)_(?P<plate>P[1-3])_(?P<wdh>W_)*UV-metric (?P<solvent>psKa|pKa).t3r`)
var str = `20F-22003_DC8_D03_1032246_P1_UV-metric psKa.t3r
20F-29001_DC8_D03_1032246_P1_W_UV-metric psKa.t3r
20F-26012_DC29_F21_1088043_P1_UV-metric psKa.t3r
20G-03010_DC60_L03_1366347_P1_UV-metric pKa.t3r
20G-04001_DC28_F19_1087258_P1_W_UV-metric psKa.t3r
21I-27003_DC245_D13_7018930044_P1_UV-metric psKa.t3r
20H-26004_DC124_J03_1216895_P2_UV-metric pKa.t3r
20I-03024_DC168_L12_105750012_P2_UV-metric psKa.t3r
20J-05001_DC132_K06_1298433_P2_W_UV-metric psKa.t3r
21I-14006_DC218_F07_1056516_P3_UV-metric psKa.t3r
test.txt`
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/