golangHow to use capture regexp
package main
import "regexp"
func main() {
  r := regexp.MustCompile(`o(h[0-9])`)
  captures := r.FindStringSubmatch("oh2f3")
}ctrl + c| package maindefault package declaration | func main() {declare  | 
| regexp.MustCompile(create regexp object and compile given pattern | .FindStringSubmatch(returns found capture groups from a given string | 
| captureswill contain list of captured values | |
Usage example
package main
import "regexp"
func main() {
  r := regexp.MustCompile(`o(h[0-9])`)
  captures := r.FindStringSubmatch("oh2f3")
  print(captures[1])
}output
h2More of Golang
- Unrmarshal example
- How to generate random int
- How to make POST (form data) request using HTTP client
- How to use proxy with HTTP client
- Marshal example
- How to iterate over a slice in reverse order
- Find the nameserver records of a domain name
- How to use range with map
- How to do case-insensitive regexp
- How to sleep for 1 hour
See more codes...