package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)\b(?:https?:\/\/)?[\w-\.$~!&'()*+,;=:%-]{3,50}:([\w-\.%$^#&'()*+,;=:%-]{3,50})@[a-zA-Z0-9.-]+(?:\.[a-zA-Z]{2,})?\b`)
var str = `### rgmz example
@----__-2as-2:password@----__-2as-2.com
### From test cases
var (
validPattern = " https://kaNydBSAodo87dSAFtsd7.com:1234@qYY3SylY7fHP "
validPattern2 = \`<p><a href="http://username:password@127.0.0.1">http://username:password@127.0.0.1</a></p>\`
invalidPattern = "https://kaNydBSAodo87dsm9asuiSAFtsd7.com.1234@qYY3SylY7fHP"
keyword = "uri"
)
### examples from chatgpt
1. \`https://user.name:pa$$word123@sub.example.com\`
2. \`http://u$er_name:my%p@$$word@api.dev.localhost\`
3. \`https://12345:67890@my-app.server123.co.uk\`
4. \`http://user~!name:pass.word@some-long-subdomain.example.org\`
5. \`https://_:__@localhost\`
6. \`https://admin:admin123@192.168.1.1\`
7. \`http://test-user:complex!password#123@server.example.io\`
8. \`https://valid_user:!valid-password@simple-host.co\`
9. \`http://username_with.dots:password_with-dashes@domain.with.subdomain.net\`
10. \`https://username:password@127.0.0.1:8080\`
11. \`http://user:pass@----__-2as-2\`
12. \`https://user@localhost\`
13. \`http://user:pass@:invalidhost\`
14. \`https://:passwordonly@hostname.com\`
15. \`ftp://username:password@hostname.com\`
16. \`https://user:password@hostname_with_underscores.com\`
17. \`http://user@:missingpassword.com\`
18. \`https://missingcolonpassword@hostname.com\`
19. \`http://user:password@-invalid-hostname.com\`
20. \`https://user:password@host..com\` `
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/