How to extract date (YYYY-MM-DD) from string using regular expression in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"regexp"
)

func main() {
	s := "go java 2020-08-23 php"

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

	submatchall := re.FindAllString(s, -1)
	for _, dt := range submatchall {
		fmt.Println(dt)
	}
}



/*
run:

2020-08-23

*/

 



answered Aug 23, 2020 by avibootz

Related questions

...