package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?im)(?:^(R)\|(\d+)\|\^*([^|]*)\|([^|]*)\|(?:([^|]*)\|)?.*$)|(?:^(P)\|(\d+)\|\|(\d+).*$)`)
var str = `P|1||322061||^|||U
O|1||138||||||||||||O
R|1|^^^BE(B)||mmol/L||C||||||20150819144937
R|2|^^^BEecf||mmol/L||C
R|3|^^^Ca++|1.17|mmol/L
R|4|^^^Ca++(7.4)||mmol/L||C
R|5|^^^HCO23-||mmol/L||C
R|6|^^^HCO3std||mmol/L||C
R|7|^^^K+|5.0|mmol/L
R|8|^^^Na+|140|mmol/L
R|9|^^^SO2c||%||C
R|10|^^^TCO2||mmol/L||C
R|11|^^^THbc||g/dL||C
R|12|^^^Temp|37.0|C
`
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/