Uma expressão regular é uma sequência de caracteres que define um padrão de pesquisa. A linguagem Go oferece suporte a expressões regulares. Uma expressão regular é usada para analisar, filtrar, validar e extrair informações significativas de texto grande, como logs, a saída gerada de outros programas, etc.
Na regexp Go, você pode encontrar uma expressão regular na string fornecida com o ajuda do método Find() . Este método retorna uma fatia que contém o texto da correspondência mais à esquerda na fatia original da expressão regular. Ou retorna nulo se nenhuma correspondência for encontrada. Este método é definido no pacote regexp, portanto, para acessar este método, você precisa importar o pacote regexp em seu programa.

Sintaxe:

func (re *Regexp) Find(s []byte) []byte

Exemplo 1:

// Go program to illustrate how to
// find regexp from the given slice
package main
  
import (
    "fmt"
    "regexp"
)
  
// Main function
func main() {
  
    // Finding regexp from the
    // given slice of bytes
    // Using  Find() method
    m := regexp.MustCompile(`geeks?`)
  
    fmt.Printf("%q\n", m.Find([]byte(`GeeksgeeksGeeks, geeks`)))
    fmt.Printf("%q\n", m.Find([]byte(`Hello! geeksForGEEKs`)))
    fmt.Printf("%q\n", m.Find([]byte(`I like Go language`)))
    fmt.Printf("%q\n", m.Find([]byte(`Hello, Welcome`)))
  
}

Saída:

"geeks"
"geeks"
""
""

Exemplo 2:

// Go program to illustrate how to
// find regexp from the given slice
package main
  
import (
    "fmt"
    "regexp"
)
  
// Main function
func main() {
  
    // Finding regexp from 
    // the given slice
    // Using Find() method
    m := regexp.MustCompile(`language`)
    res := m.Find([]byte(`I like Go language this language is "+
                          "very easy to learn and understand`))
  
    if res == nil {
  
        fmt.Printf("Found: %q ", res)
    } else {
        fmt.Printf("Found: %q", res)
    }
}

Saída:

Found: "language"