O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The FindString or FindAllString functions are the simplest ways to find the matching pattern in the given string. The only difference is that the FindString method of Regexp will return only the first occurrence. On the other hand, the FindAllString, as the name suggests, returns a slice of strings with all occurrences.

The Regexp type offers a rich set of FindXXX methods. This recipe describes only the String variations that are usually most useful. Note that the preceding code uses the MustCompile function of the regexp package, which panics if the compilation of the regular expression fails.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required