-2

I need to extract a part of a string in Golang for a dashboard in Google Data Studio. This is the string:

ABC - What I need::Other Information I do not need

To get the part between the hyphen and the first colon I have tried ([\\-].*[\\:]), which includes both, the hyphen and the colons.

That might be an easy question for more experienced RegExp users, but how do I match only the words in between?

logi-kal
  • 7,107
  • 6
  • 31
  • 43
pscl
  • 15
  • 1
  • 4

1 Answers1

1

You may use this:

-(.*?):

Here the first capture group is your desired result. Example

Sample Source: ( run here )

package main

import (
    "fmt"
    "regexp"
)

func main() {
    var re = regexp.MustCompile(`(?m)-(.*?):`)
    var str = `ABC - What I need::Other Information I do not need`
    rs:=re.FindStringSubmatch(str)
    fmt.Println(rs[1])

}
Mustofa Rizwan
  • 10,215
  • 2
  • 28
  • 43