Skip to main content

Extract date of string using go programming

  import (

"regexp"
"fmt"
)

func main() {
exactDate()
}

func exactDate() {
str1 := "If I am 20 years 10 months and 14 days old as of August 17,2016 then my DOB would be 1995-10-03"

re := regexp.MustCompile(`\d{4}-\d{2}-\d{2}`)

b := re.MatchString(str1)

if b {
val := re.FindAllString(str1, 1)
fmt.Println(val[0])
}
}

Comments

Popular posts from this blog

Go programming basic

  https://cccabs-service.in/blogs/interface-and-class-example-in-golang-program implementation  link Interface and Class Example in golang program // how to implement interface in golang programming // how to create class in golang programming // how to create a struct in golang program here is example promgram package main import ( "fmt" "log" ) type sender interface { send() (string, error) } type receiver interface { receive(string) error } type sendAndReceive interface { sender receiver } type Data struct { Message string } func (d Data) send() (string, error) { if d.Message == "" { return "", fmt.Errorf("Message should not be empty") } result := fmt.Sprintf("%s data...\n", d.Message) return result, nil } func (d Data) receive(data string) error { if d.Message == "" { return fmt.Errorf("data should not exmpty") } d.Message = data return nil } func Display(dis sendAndReceiv...