V
V
Vladimir Grabko2016-06-11 13:14:35
go
Vladimir Grabko, 2016-06-11 13:14:35

Why does it search for only 1 email and end?

str := `email: [email protected] email: [email protected]`

  r := regexp.MustCompile("\\b[A-Za-z0-9._%+-][email protected][A-Za-z0-9.-]+\\.[A-Za-z]{2,6}\\b")

  for index, match := range r.FindStringSubmatch(str) {
    fmt.Printf("[%d] %s\n", index, match)
  }

I want to find all emails in a string but I only find the first one.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-06-11
@VGrabko

^ - search from the beginning of the line.
$ - search to the end of the line.
Try to remove them.
UPD. {2,4} - a bit outdated already, there are longer TLDs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question