Need some guidance on creating a regex that will identify part of the URL.
URL1: test-project-233-TEST-ENDPOINT.test.as.ds.abcdefg.com
URL2: test-project-124-ENDPOINT.test.dd.ad.gf.abcdefg.com
The goal is to build a regex that can parse out "test-project-233" and "test-project-124" for me.
I've already tried to google around and finding complex regex differentiation. It would be awesome to get some pointers on this issue.
Thanks
The regex would be ([a-z]*-){2}\d*
. In order to simplify your research, go on https://regexr.com/ and past your links in. From there you will be able to create your regex step by step easily.
A regexp is not needed. Just slice off the start of the string:
for _, s := range []string{
"test-project-233-TEST-ENDPOINT.test.as.ds.abcdefg.com",
"test-project-124-ENDPOINT.test.dd.ad.gf.abcdefg.com",
} {
fmt.Println(s[:16])
}