Regular expressions
A regular expression offers efficient methods to ensure that textual data matches a given pattern, searches for patterns, extracts, and replaces parts of text. Usually, you compile a regular expression once and then use that compiled regular expression many times to efficiently validate, search, extract, or replace parts of strings.
Validating input
Format validation is the process of ensuring that data coming from user input or other sources is in a recognized format. Regular expressions can be an effective tool for such validation.
How to do it...
Use precompiled regular expressions to validate input values that should fit a pattern.
package main import ( "fmt" "regexp" ) var integerRegexp = regexp.MustCompile("^[0-9]+$") func main() { fmt.Println(integerRegexp.MatchString("123")) // true ...