It's an annoying oversight, you have to create your own function.

Something like:

func indexAt(s, sep string, n int) int {
    idx := strings.Index(s[n:], sep)
    if idx > -1 {
        idx += n
    }
    return idx
}
Answer from OneOfOne on Stack Overflow
๐ŸŒ
TutorialKart
tutorialkart.com โ€บ golang-tutorial โ€บ golang-string-get-index-of-substr
How to find Index of Substring in a String in Go?
May 28, 2021 - To get the index of a substring in a string in Go programming, call strings.Index() function and pass the string and substring as arguments to this function.
Discussions

Help: Finding all occurrences of a text inside a string, between a given start and finish
Your problem isn't particularly well defined, but as u/AYBABTME said, regexps are for this kind of thing; anything else you do, you'll end up reinventing them. Depending on exactly what your problem is, I thought this might help: http://play.golang.org/p/WCPKhIGvNj Of the things I've pointed out in the code, the fact that [[:upper:]] & etc. are exactly what is described in http://golang.org/pkg/regexp/syntax/ (and so there is no easy way to say "anything uppercase") means that if that is a problem for you, you're going to have to reinvent them anyway. More on reddit.com
๐ŸŒ r/golang
6
4
June 22, 2014
proposal: strings: add multiple string search ContainsAnySubstring and IndexAnySubstring
I'd like to propose a new group of string search functions in the strings package that can efficiently search for multiple needles. Rationale Looking at StackOverflow, the common advice given t... More on github.com
๐ŸŒ github.com
4
February 11, 2022
string - How to find a character index in Golang? - Stack Overflow
I'm trying to find "@" string character in Go but I cannot find a way to do it. I know how to index characters like "HELLO[1]" which would output "E". However I'm trying to find index number of the... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Find all index of occurrences of character in a string
Why would you even need the indexOf method? The naive, straightforward approach is to use .charAt and to loop over the characters in the string using a forloop. (TBH, .indexOf does exactly the same under the hood, just adds a starting index and it stops on the first occurrence). Honestly, the only way to learn proper programming is to stop searching for solutions and to sit down and try to work out your own solutions, because otherwise, you get in over your head, as in your case ending with code that you might have been able to somewhat reproduce, but that you don't understand. Start with pen(cil) and paper and try to figure out how you, the person, would address a problem. Only once you have found a solution start thinking about programming it. And don't memorize. Especially not code. Code adapts to the situation and is only the end product, not the starting point. Edit: Very mature move/s of you blocking people that offer help and advice to you just because you feel personally attacked or disagree with what has been said. More on reddit.com
๐ŸŒ r/learnjava
10
3
October 7, 2024
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ go โ€บ strings โ€บ index()
Go | Strings | Index() | Codecademy
July 6, 2023 - The Index() function returns the index value of the first occurrence of a substring in the original string, otherwise it returns -1 if the substring is not present in the original string.
๐ŸŒ
Reddit
reddit.com โ€บ r/golang โ€บ help: finding all occurrences of a text inside a string, between a given start and finish
r/golang on Reddit: Help: Finding all occurrences of a text inside a string, between a given start and finish
June 22, 2014 -

Hello everyone,

I'm tring to do something interesting, but I don't know how to do it the Go way. The problem I'm trying to solve is: given a long string of text like:

Fabio vel iudice vincam, sunt in culpa qui officia. Ullamco laboris nisi ut aliquid ex ea commodi consequat. At nos hinc posthac, sitientis piros Afros. A communi observantia non est recedendum. Quisque placerat facilisis egestas cillum dolore.

I need a function that helps me find all occurrences of something between two other strings of text, all of their occurrences, i.e. if I search for anything between un and (space) I got a slice of strings with a "t" at the zero position and a "i" at the first position (that because "sunt in" matches the description of anything between "un" and " " and also "communi observantia" matches, because "commUNi ")

I've just made a function but it only finds the first occurrence and I might think that this is not the Go way of doing things. Look here: http://play.golang.org/p/NuVJGfQ4GB

๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-find-the-index-of-a-string-in-golang
How to find the Index of a string in Golang?
If the substring is not available in the given string, then it returns -1. ... package main import ( "fmt" "strings" ) // Main function func main() { // Initializing the Strings x := "Learn Golang on Tutorialspoint" // Display the Strings fmt.Println("Given String:", x) // Using the Index Function result1 := strings.Index(x, "Golang") result2 := strings.Index(x, "TUTORIALSPOINT") // Display the Index Output fmt.Println("Index of 'Golang' in the Given String:", result1) fmt.Println("Index 'TUTORIALSPOINT' in the Given String:", result2) }
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ golang-program-to-get-the-index-of-the-substring-in-a-string
Golang Program to get the index of the substring in a string
February 17, 2023 - Step 2 ? Then we need to create the function indexOfString(). This function takes the string and the substring as argument to the function and returns an integer value. Step 3 ? Inside this function we are using a for loop to iterate over the ...
๐ŸŒ
Dot Net Perls
dotnetperls.com โ€บ index-go
Go - strings.Index, LastIndex Funcs - Dot Net Perls
package main import ( "fmt" "strings" ) func main() { value := "cat dog" // Get index of this substring. result := strings.Index(value, "dog") fmt.Println(result) } ... This searches from right to left. It begins its search at the last index and proceeds to the first index.
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ practicing-string-operations-and-type-conversions-in-go โ€บ lessons โ€บ string-manipulation-in-go-finding-substring-occurrences
String Manipulation in Go: Finding Substring Occurrences
The strings.Index function returns the index of the first occurrence of the substring or -1 if it is not present. ... The next step is to find subsequent instances of the substring in the original string.
Find elsewhere
๐ŸŒ
Leapcell
leapcell.io โ€บ blog โ€บ extracting-substrings-in-go
Extracting Substrings in Go | Leapcell
July 25, 2025 - The strings package offers functions like HasPrefix, HasSuffix, Contains, Index, and Split to work with substrings: package main import ( "fmt" "strings" ) func main() { str := "Hello, World!" // Check if the string contains a substring contains := strings.Contains(str, "World") fmt.Println(contains) // Output: true // Find the index of a substring index := strings.Index(str, "World") fmt.Println(index) // Output: 7 // Split the string parts := strings.Split(str, ", ") fmt.Println(parts) // Output: [Hello World!] }
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-find-the-index-value-of-specified-string-in-golang
How to find the index value of specified string in Golang? | GeeksforGeeks
August 26, 2019 - The LastIndex() function from the bytes package returns the last index of a specified value in a byte slice, or -1 if the value is not found.Examplepackage mainimport ( "bytes" "fmt")func ...
๐ŸŒ
ZetCode
zetcode.com โ€บ golang โ€บ regexp-findstringsubmatchindex
Finding String Submatch Indexes with Regular Expressions in Go
package main import ( "fmt" "regexp" ... str[indices[0]:indices[1]] fmt.Printf("Found '%s' at %d-%d\n", word, indices[0], indices[1]) } } FindAllStringSubmatchIndex returns a slice of index slices....
๐ŸŒ
Bacancy Technology
bacancytechnology.com โ€บ qanda โ€บ golang โ€บ extracting-substrings-in-go
Simplify Extracting Substrings in Go | Expert Insights
In this example, originalString[7:13] extracts the substring starting from index 7 up to, but not including, index 13. The strings package in the standard library provides a variety of functions for string manipulation, including substring extraction. The Substring function allows you to extract substrings based on starting and ending indices.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-is-the-index-function-in-go
What is the Index() function in Go?
This method takes a string s and another string substr to search as inputs. This method returns the index of the first occurrence of the substring substr in the input string s.
๐ŸŒ
Sling Academy
slingacademy.com โ€บ article โ€บ searching-for-substrings-in-go-practical-techniques
Searching for Substrings in Go: Practical Techniques - Sling Academy
It returns the position of the ... strings.Index(mainString, subString) fmt.Println("Index:", index) } To find all occurrences of a substring, you can repeatedly use strings.Index in a loop to achieve this....
๐ŸŒ
HowDev
how.dev โ€บ answers โ€บ what-is-stringsindexany-in-go
What is strings.IndexAny() in Go?
September 28, 2021 - It returns the first occurrence of the Unicode code points from the input substring chars, which are present in the input string s. It returns -1 if none of the Unicode code points from the chars string are present in s. Using IndexAny() to find the index of any of the input chars from the string
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ go language โ€บ golang-finding-index-of-the-regular-expression-present-in-string
Golang | Finding Index of the Regular Expression present in String - GeeksforGeeks
September 5, 2019 - // 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 := ...
๐ŸŒ
Programming.Guide
programming.guide โ€บ go โ€บ regexp-find-all-matches.html
Go: Find all substrings matching a regexp | Programming.Guide
There are several more search functions available in the regexp package. The strings All, String, Submatch, and Index can be combined to form the methods: