I have a string like this (4 words separated by dot)
Exactfoobar.foobar-_nocaps.foobar-_nocaps.foobar-_caps
I need to write a regex to find the pattern as above.
- There could be 4 or more fields separated by a dot
- The first word should be exactly
Exactfoobar.
- The 2nd and 3rd word can't have caps but can have -_
- The 4th word and so on can have caps with -_
I was thinking of using groups but its not working here:
^Exactfoobar\.([a-z0-9][a-z0-9_\-.])+([a-z0-9][a-zA-Z0-9_\-.])+$
How should I think about matching a string after another string. Is it possible?
Trying this in golang but cant seem to get the above regex right
package main
import (
"fmt"
"regexp"
)
func main() {
var validID = regexp.MustCompile(`^ Exactfoobar\.([a-z0-9][a-z0-9_\-.])+([a-z0-9][a-z0-9_\-.])+$`)
fmt.Println(validID.MatchString("Exactfoobar.somestring.some_other-string.someStringwithCaps"))
}
Result:
false
Thanks