We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package main import ( "fmt" "regexp" ) func main() { re := regexp.MustCompile(`^\d+$`) fmt.Println(re.MatchString("13877474")) }
package main import ( "fmt"; "regexp" ) func main() { re := regexp.MustCompile("\\$\\{(.*?)\\}") match := re.FindStringSubmatch("git commit -m '${abc}'") fmt.Println(match) }
SKU有两类一类是定值的比如"sku_goods1_9000_0",这种就需要验证下单参数的中的金额与SKU中的金额是否是一样, 另外一种充值订单对应的SKU不是定值的就不用验证,比如"sku_recharge_other_0",写一个函数完成这个功能。
// 检查创建订单时参数里的amount与skuSymbol中的amount是否一致 func checkSkuAmount(skuSymbol string, amount int64) bool { if strings.Contains(skuSymbol, "other") { return true } re := regexp.MustCompile(`[A-Za-z_]+?(\d+?)_\d+$`) match := re.FindStringSubmatch(skuSymbol) if match == nil { return false } skuAmount, err := strconv.ParseInt(match[1], 10, 64) if err != nil || skuAmount != amount { return false } return true }
隐藏姓名中间部分,只展示首尾
func HideUserName(userName string) string { if userName == "" { return "" } re := regexp.MustCompile(`^(.).+?(.)?$`) result := re.ReplaceAllString(userName, `$1*$2`) return result }
golang 正则库CheatSheet
The text was updated successfully, but these errors were encountered:
No branches or pull requests
验证字符串匹配模式
子模式匹配
SKU有两类一类是定值的比如"sku_goods1_9000_0",这种就需要验证下单参数的中的金额与SKU中的金额是否是一样, 另外一种充值订单对应的SKU不是定值的就不用验证,比如"sku_recharge_other_0",写一个函数完成这个功能。
正则替换
隐藏姓名中间部分,只展示首尾
golang 正则库CheatSheet
The text was updated successfully, but these errors were encountered: