本文整理汇总了Golang中regexp.Regexp.ReplaceAllLiteralString方法的典型用法代码示例。如果您正苦于以下问题:Golang Regexp.ReplaceAllLiteralString方法的具体用法?Golang Regexp.ReplaceAllLiteralString怎么用?Golang Regexp.ReplaceAllLiteralString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类regexp.Regexp
的用法示例。
在下文中一共展示了Regexp.ReplaceAllLiteralString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: extractComponent
func extractComponent(component string, re *regexp.Regexp) (string, bool) {
// TODO: make sure there's no extra text before the match of the regexp
if re.MatchString(component) {
value := strings.TrimSpace(re.ReplaceAllLiteralString(component, ""))
return value, true
} else {
return "", false
}
}
示例2: outBytes
// outBytes takes the proc.net.dev string, and the interface name, and returns the bytes field
func outBytes(procNetDev, iface string, multipleSpaceRegex *regexp.Regexp) (int64, error) {
if procNetDev == "" {
return 0, fmt.Errorf("procNetDev empty")
}
if iface == "" {
return 0, fmt.Errorf("iface empty")
}
ifacePos := strings.Index(procNetDev, iface)
if ifacePos == -1 {
return 0, fmt.Errorf("interface '%s' not found in proc.net.dev '%s'", iface, procNetDev)
}
procNetDevIfaceBytes := procNetDev[ifacePos+len(iface)+1:]
procNetDevIfaceBytes = strings.TrimLeft(procNetDevIfaceBytes, " ")
procNetDevIfaceBytes = multipleSpaceRegex.ReplaceAllLiteralString(procNetDevIfaceBytes, " ")
procNetDevIfaceBytesArr := strings.Split(procNetDevIfaceBytes, " ") // this could be made faster with a custom function (DFA?) that splits and ignores duplicate spaces at the same time
if len(procNetDevIfaceBytesArr) < 10 {
return 0, fmt.Errorf("proc.net.dev iface '%v' unknown format '%s'", iface, procNetDev)
}
procNetDevIfaceBytes = procNetDevIfaceBytesArr[8]
return strconv.ParseInt(procNetDevIfaceBytes, 10, 64)
}