trim square brackets in SquareBracketsLanguageParserRegex
This commit is contained in:
parent
d4e5e65935
commit
517518dd30
@ -7,5 +7,5 @@ type LanguageParserFunc func(str string) []string
|
||||
var SquareBracketsLanguageParserRegex = regexp.MustCompile(`\[.+?\]`)
|
||||
|
||||
func SquareBracketsLanguageParser(str string) []string {
|
||||
return SquareBracketsLanguageParserRegex.FindAllString(str, -1)
|
||||
return TrimPrefixSuffix(SquareBracketsLanguageParserRegex.FindAllString(str, -1), "[", "]")
|
||||
}
|
||||
|
13
utils.go
13
utils.go
@ -1,6 +1,9 @@
|
||||
package parsers
|
||||
|
||||
import "strconv"
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func atoi(s string) (int, bool) {
|
||||
v, err := strconv.Atoi(s)
|
||||
@ -9,3 +12,11 @@ func atoi(s string) (int, bool) {
|
||||
}
|
||||
return v, true
|
||||
}
|
||||
|
||||
func TrimPrefixSuffix(arr []string, prefix, suffix string) []string {
|
||||
trims := make([]string, 0, len(arr))
|
||||
for _, str := range arr {
|
||||
trims = append(trims, strings.TrimSuffix(strings.TrimPrefix(str, prefix), suffix))
|
||||
}
|
||||
return trims
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user