Search Gear Notes

Search Gear #19 Regular Expressions

func getItem(entries toml.Value) func() (string, error) { i := -1 return func() (string, error) { rExpression := regexp.MustCompile(“(-([A-Z]+|[A-Z]+[1-9])-)”) i += 1 if i < len(entries.AsArray()) { if rExpression.FindString(entries.AsArray()[i].AsString()) != "" { foundString := rExpression.FindString(entries.AsArray()[i].AsString()) switch foundString { case "-YY-": replaceWith := strconv.Itoa(time.Now().Year()) entity := rExpression.ReplaceAllLiteralString(entries.AsArray()[i].AsString(), replaceWith[2:4]) return entity, nil case "-YY1-": replaceWith := strconv.Itoa(time.Now().Year() +…

Advertisement