A Regular Expression (or RegEx) is a special sequence of characters that defines a search pattern that is used for matching specific text. In Golang, there’s a built-in package for regular expressions, called the regexp package which contains all list of actions like filtering, replacing, validating, or extracting. It uses the RE2 syntax standards. The MatchString() function reports whether the string passed as a parameter contains any match of the regular expression pattern.
func MatchString(pattern string, s string)
Returns: matched bool, err error
Match: true Error: <nil> Match: false Error: <nil> Match: false Error: error parsing regexp: missing closing ): `geek(s`
To store complicated regular expressions for reuse later, Compile() method parses a regular expression and returns a Regexp object if successful which can be used to match the text. Prototype of the function is:
func Compile(expr string) (*Regexp, error)
There are other various methods provided in the regexp package to match strings as shown:
[7 11]  20024-vani_g [[7 11] [15 19] [23 27]] All+I+do+is+code+everytime. All I dO Is cOdE EvErytImE.
- How to Split Text Using Regex in Golang?
- Function to escape regex patterns before applied in PHP
- ES6 | RegEx
- Split a String into columns using regex in pandas DataFrame
- Perl | Grouping and Alternation in Regex
- Perl | Anchors in Regex
- Perl | Assertions in Regex
- Perl | Extract IP Address from a String using Regex
- How to get YouTube video ID with PHP Regex ?
- How to convert a slice of bytes in uppercase in Golang?
- Golang program that uses fallthrough keyword
- math.Lgamma() Function in Golang with Examples
- math.Float64bits() Function in Golang With Examples
- How to check equality of slices of bytes in Golang?
- atomic.AddInt64() Function in Golang With Examples
- atomic.StoreInt64() Function in Golang With Examples
- reflect.FieldByIndex() Function in Golang with Examples
- string.Contains Function in Golang with Examples
- bits.Sub() Function in Golang with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.