Golang regexp.FindAll() function example
package regexp
Golang regexp.FindAll() function usage example
package main
import (
"fmt"
"regexp"
)
func main() {
// regular expression pattern
regE := regexp.MustCompile("/oid/([\\d]+)/")
// simulate a search
// first convert string to byte for Find() function
searchByte := []byte("/oid/1/something_else/oid/2/")
matchSlice := regE.Find(searchByte)
fmt.Printf("%s \n", matchSlice) // if found, return leftmost match, without 'abc'
matchSlice2 := regE.FindAll(searchByte, 500)
fmt.Printf("%s \n", matchSlice2) // if found, return all successive matches
}
Output :
/oid/1/
[/oid/1/ /oid/2/]
Reference :
Advertisement
Something interesting
Tutorials
+17.5k Golang : Clone with pointer and modify value
+4.7k Linux/MacOSX : How to symlink a file?
+5.9k Golang : Generate multiplication table from an integer example
+11.2k Golang : Calculate Relative Strength Index(RSI) example
+11.6k Golang : Fuzzy string search or approximate string matching example
+6.5k Golang : Combine slices of complex numbers and operation example
+24.5k Golang : Change file read or write permission example
+4.7k Fix Google Analytics Redundant Hostnames problem
+7.6k Golang : Convert(cast) io.Reader type to string
+7.5k Golang : Gorrila set route name and get the current route name
+19.2k Golang : Check whether a network interface is up on your machine
+19.9k Golang : Measure http.Get() execution time