[Golang] Check If a String Exists in File
Check if a string exists in file via Go regexp package.
import (
"io/ioutil"
"regexp"
)
func IsExist(str, filepath string) bool {
b, err := ioutil.ReadFile(filepath)
if err != nil {
panic(err)
}
isExist, err := regexp.Match(str, b)
if err != nil {
panic(err)
}
return isExist
}
References:
[1] | func Match - regexp - The Go Programming Language |