Scott

regexp \S 的妙用 2 years ago

go
regexp
432个字符
共有183人围观

博客大纲

\S* vs .*

  • *表数目
  • .表任意字符(包含空白字符,不含\n)范围更大
  • \S表非空字符,相对来说范围更小更精准
package main

import (
	"fmt"
	"io/ioutil"
	"regexp"
)

var re = regexp.MustCompile(`"(\S*).github-scott-bear.workers.dev"`)

func main() {
	bs, _ := ioutil.ReadFile("config.json")
	arr := re.FindAllStringSubmatch(string(bs), -1)
	fmt.Println(arr[0][1]) //young-leaf-8425
}

更多可以参考: https://tool.oschina.net/uploads/apidocs/jquery/regexp.html