Reusable regex in Golang for rule system.

99 views
Skip to first unread message

David Sofo

unread,
Oct 20, 2016, 8:06:56 AM10/20/16
to golang-nuts

Hi,
I ma new to Go Regex.

I want to have a set of reusable rules of regex in golang easy to edit or update. For example a regex for date can be splitted in day, month and year :

year=d{4}
month=
d{2}
day=
d{2}

and for date we can have as following: date=year-month-day


Is it possible in golang? Can we add human readable comment to regex?

Any suggestion is welcome.

Thank you
David




Paul Borman

unread,
Oct 20, 2016, 10:07:03 AM10/20/16
to David Sofo, golang-nuts
Check out time.Parse:

t := time.Parse("2006-01-02", inputString)
year := t.Year()
month := t.Month()
day := t.Day()

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages