Golang | Finding Index of the Regular Expression present in String Last Updated : 05 Sep, 2019 Comments Improve Suggest changes Like Article Like Report 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 find the leftmost index value of the specified regular expression in the given string with the help of the FindStringIndex() method. This method returns a two-element slice of integers which defines the location of the leftmost match in the given string of the regular expression and the match like str[loc[0]:loc[1]]. Or it will return nil if no match found. This method is defined under the regexp package, so for accessing this method you need to import the regexp package in your program. Syntax: func (re *Regexp) FindStringIndex(str string) (loc []int) Example 1: C // Go program to illustrate how to find the // index value of the regexp in the given string package main import ( "fmt" "regexp" ) // Main function func main() { // Finding index regexp // from the given string // Using FindStringIndex() method m := regexp.MustCompile(`ee`) fmt.Println(m.FindStringIndex("GeeksgeeksGeeks, geeks")) fmt.Println(m.FindStringIndex("Hello! geeksForGEEKs")) fmt.Println(m.FindStringIndex("I like Go language")) fmt.Println(m.FindStringIndex("Hello, Welcome")) } Output: [1 3] [8 10] [] [] Example 2: C // Go program to illustrate how to find the index // value of the regexp in the given string package main import ( "fmt" "regexp" ) // Main function func main() { // Finding the regexp // from the given string // Using Find() method m := regexp.MustCompile(`345`) res := m.FindString("I45, like345, Go-234 langu34age") // Finding the index value of regexp in the given string // UsingFindStringIndex() method r := m.FindStringIndex("I45, like345, Go-234 langu34age") fmt.Printf("Found: %s with index value: %d", res, r) } Output: Found: 345 with index value: [9 12] Comment More infoAdvertise with us Next Article Golang | Finding Index of the Regular Expression present in String ankita_saini Follow Improve Article Tags : Go Language Golang Golang-String Similar Reads Golang | Finding Index of the Regular Expression present in Slice 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. I 2 min read Golang | Extracting a Regular Expression from the String 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. I 2 min read strings.IndexRune() Function in Golang With Examples strings.IndexRune() Function in Golang is used to find the first index of the specified rune in the given string. It is defined under the string package so, you have to import string package in your program for accessing IndexRune function Syntax: func IndexRune(str string, r rune) int This function 2 min read Golang | How to find the index of rune in the string? In Go language, strings are different from other languages like Java, C++, Python, etc. It is a sequence of variable-width characters where each and every character is represented by one or more bytes using UTF-8 Encoding. In the Go strings, you can also find the first index of the specified rune in 3 min read strings.IndexByte() Function in Golang With Examples strings.IndexByte() Function in Golang returns the index of the first instance of the given byte in the original string. If the given byte is not available in the original string, then this method will return -1. Syntax: func IndexByte(str string, b byte) int Here, str is the original string and b i 1 min read strings.IndexFunc() Function in Golang With Examples strings.IndexFunc() Function in Golang is used to returns the index into s of the first Unicode code point satisfying f(c), or -1 if none do. Syntax: func IndexFunc(str string, f func(rune) bool) int Here, str is string which may contain Unicode code point and f is func which validates the Unicode p 1 min read Golang | Extracting all the Regular Expression from the String 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. I 2 min read strings.Index() Function in Golang With Examples strings.Index() Function in Golang is used to get the first instance of a specified substring. If the substring is not found, then this method will return -1. Syntax: func Index(str, sbstr string) int Here, str is the original string and sbstr is a string whose we want to find index value. Example 1 2 min read strings.IndexAny() Function in Golang With Examples strings.IndexAny() Function in Golang is used to returns the index of the first instance of any Unicode code point from chars in the original string. If the Unicode code point from chars is not available in the original string, then this method will return -1. Syntax: func IndexAny(str, charstr stri 2 min read strings.LastIndexByte() Function in Golang With Examples strings.LastIndexByte() Function in Golang returns the index of the last instance of the given byte in the original string. If the given byte is not available in the original string, then this method will return -1. Syntax: func LastIndexByte(str string, b byte) int Here, str is the original string 1 min read Like