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.
- ES6 | RegEx
- Perl | Anchors in Regex
- Perl | Assertions in Regex
- How to get YouTube video ID with PHP Regex ?
- Perl | Grouping and Alternation in Regex
- Perl | Extract IP Address from a String using Regex
- Function to escape regex patterns before applied in PHP
- Split a String into columns using regex in pandas DataFrame
- Zero value in Golang
- Reflection in Golang
- Channel in Golang
- Methods in Golang
- Methods With Same Name in Golang
- Hello World in Golang
- Closures in Golang
- Interfaces in Golang
- Packages in Golang
- Composition in Golang
- Slices in Golang
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.