blob: a1084462c51b04e240f4b67c430942f711488eae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
package util
import (
"regexp"
"strings"
)
var (
pgArrayReg = regexp.MustCompile(`(((?P<value>(([^",\\{}\s(NULL)])+|"([^"\\]|\\"|\\\\)*")))(,)?)`)
pgValueIdx int
)
func init() {
for i, subexp := range pgArrayReg.SubexpNames() {
if subexp == "value" {
pgValueIdx = i
break
}
}
}
func PGArray(array []byte) []string {
var results []string
matches := pgArrayReg.FindAllStringSubmatch(string(array), -1)
for _, match := range matches {
s := match[pgValueIdx]
s = strings.Trim(s, "\"")
results = append(results, s)
}
return results
}
|