Go Regex

Go Regex package is used for searching string. To search a string, we need to provide a pattern of the string.

We need to compile the pattern into the regex object so that we can invoke methods through it.

The regex object can be retrieved by using compile() and mustcompile() functions. Now we can use functions to find strings such as FindString(), FindStringSubmatch(), FindStringIndex() etc.

Go Regex Example 1




The FindString() method returns a string having the text of the left most match. If no match is found, empty string is returned.

Go Regex Example 2


[6 10]
[2 6]

Go Regex Example 3

we can also use FindStringSubmatch() method which returns a slice of strings having the text of the leftmost match and the matches. If no match is found, the return value is an empty string.


[flying ly]
[floating loat]

Process finished with exit code 0

Next TopicGo Struct

Hot Tutorials

Contact US


Go Regex