Need help with fetching word from a string.
STRING | WORD NEEDS TO BE FETCHED |
---|---|
“A = 2&& B = 2 && func1(A) && func2(B)” | func1, func2 |
“func1(A)” | func1 |
“B = 2 && func2(A)” | func2 |
I have tried with following regex
package main
import (
"fmt"
"regexp"
)
func main() {
var re = regexp.MustCompile(`s+(?:w+_w+)`)
var str = `func1(A)`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
But this returning not any word incase there’s no space eg: for string “func1(A)”. This is working as expected when the word has a space before. Any help would be appreciated