Wik*_*żew 20

\s\p{Zs}ReplaceAllStringFunc

因此,我建议使用两个正则表达式:

^[\s\p{Zs}]+|[\s\p{Zs}]+$[\s\p{Zs}]{2,}

示例代码:

package main

import (
    "fmt"
    "regexp"
)

func main() {
    input := "   Text   More here     "
    re_leadclose_whtsp := regexp.MustCompile(`^[\s\p{Zs}]+|[\s\p{Zs}]+$`)
    re_inside_whtsp := regexp.MustCompile(`[\s\p{Zs}]{2,}`)
    final := re_leadclose_whtsp.ReplaceAllString(input, "")
    final = re_inside_whtsp.ReplaceAllString(final, " ")
    fmt.Println(final)
}