How to split a string by multiple delimiters

前端 未结 5 1152
长发绾君心
长发绾君心 2021-02-20 03:13

I want to parse a string xxxxx:yyyyy:zzz.aaa.bbb.cc:dd:ee:ff to a struct in Go, how can I do it with multiple delimiter \':\' and \'.\'.

Edit:

I want to split the

5条回答
  •  你的背包
    2021-02-20 03:55

    You can use regex for splitting your string

    import "regexp"
    
    func splitWord(word string) []string {
        array := regexp.MustCompile("[\\:\\,\\.\\s]+").Split(word, -1)
        return array
    }
    

提交回复
热议问题