VOOZH about

URL: https://www.geeksforgeeks.org/go-language/golang-checking-the-byte-of-slice-for-specified-regular-expression/

⇱ Golang | Checking the byte of slice for specified regular expression - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Golang | Checking the byte of slice for specified regular expression

Last Updated : 5 Sep, 2019
A regular expression is a sequence of characters which define a search pattern. Go language support regular expressions. A regular expression is used for parsing, filtering, validating, and extracting meaningful information from large text, like logs, the output generated from other programs, etc. In Go regexp, you are allowed to check whether the given slice byte contains any match of the specified regular expression pattern with the help of Match() function. This function is defined under the regexp package, so for accessing this method you need to import the regexp package in your program. Syntax:
func Match(p string, s []byte) (result bool, err error)
Here, p represents the pattern and s represents a slice of bytes. This function returns true if the pattern matched or return false if the pattern does not match. And also return an error if found. Example 1: Output:
Result and Error is: true <nil>
Result and Error is: false <nil>
Result and Error is: true <nil>
Result and Error is: false <nil>
Result and Error is: false <nil>
Result and Error is: true <nil>
Result and Error is: true <nil>
Result and Error is: false <nil>
Example 2: Output:
true <nil>
false <nil>
false <nil>
false error parsing regexp: missing closing ): `e(ks`
Comment
Article Tags:

Explore