I want to take the first 4 numbers of the string phone numbers
example
phoneNumber := "081911254966"
I want to get from regex Go and get the result "0819"
I want to take the first 4 numbers of the string phone numbers
example
phoneNumber := "081911254966"
I want to get from regex Go and get the result "0819"
 
    
     
    
    package main
import (
    "fmt"
    "regexp"
)
func main() {
    phoneNumber := "081911254966"
    r := regexp.MustCompile(`^\d{4}`).FindString(phoneNumber)
    r2 := regexp.MustCompile(`\d{4}`).FindString("trash text 081911254966 trash text")
    // if not need regexp
    fmt.Println(phoneNumber[:4])
    fmt.Println(r)
    fmt.Println(r2)
}
0819
0819
0819
