π Regex β
go
import (
"github.com/thuongtruong109/gouse"
)
1. Regex is match β
Description: Check if the input string is match with regex pattern
Input params: (pattern, input string)
--> Note: regex pattern is not include one of (^, $, /g)
go
func RegexIsMatch() {
gouse.Println("Match string with regex: ", gouse.IsMatchReg(`[a-z]+\s[a-z]+`, "hello world"))
}
2. Regex match index β
Description: Find the first index and value of the match regex pattern
Input params: (pattern, input string)
--> Note: regex pattern is not include one of (^, $, /g)
go
func RegexMatchIndex() {
paragraph := "I think Ruth's dog is cuter than your dog!"
matchIdx := gouse.MatchIndexReg(`[^\w\s']`, paragraph)
if matchIdx != -1 {
gouse.Printf("Match with regex (index: %d, value: %s)\n", matchIdx, string(paragraph[matchIdx]))
} else {
println("Not found index match regex")
}
}
3. Regex match β
Description: Find all index and value of the match regex pattern
Input params: (pattern, input string)
--> Note: regex pattern is not include one of (^, $, /g)
go
func RegexMatch() {
gouse.Println("Match string with regex: ", gouse.MatchReg(`[A-Z]`, "Hello World 123"))
}