O
O
onlinejunior2019-12-04 09:04:03
go
onlinejunior, 2019-12-04 09:04:03

How to write a regular expression equivalent to php in golang?

I can't figure out how to make a regular expression in Go:

preg_match('/config = {(.*?)};/', $response->body, $result);

Is there an exact equivalent?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WinPooh32, 2019-12-04
@WinPooh32

MustCompile and MatchString

example
package main

import (
  "fmt"
  "regexp"
)

func main() {
  re := regexp.MustCompile(`(gopher){2}`)
  fmt.Println(re.MatchString("gopher"))
  fmt.Println(re.MatchString("gophergopher"))
  fmt.Println(re.MatchString("gophergophergopher"))
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question