Regex Not Capturing Exact IP Address Format in Go - implementing Leading Zeros
I'm confused about I tried several approaches but none seem to work. I'm working on a Go application where I need to validate and capture IPv4 addresses from a large text file. However, I'm running into issues with leading zeros. My current regex is `^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$`, but this is allowing IPs like `192.168.01.1`, which shouldn't be valid. I've tried adding a negative lookahead to prevent leading zeros, but I need to seem to get the syntax right. Here's the updated regex I've been experimenting with: ```go regex := `^(?!.*\b0\d+)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$` ``` However, this regex fails to match valid IPs like `192.168.1.1`. I also considered using a more complex pattern that would individually check each octet: ```go regex := `^(?!.*\b0\d+)((25[0-5]|(2[0-4][0-9]|(1[0-9]{2}|[1-9]?[0-9])))(\.(?!0)\d{1,3}){3})$` ``` This regex is getting closer, but it's still not matching `10.0.0.0`. When I run this against my text file, I see unexpected matches and I need to figure out where the logic is breaking down. Any advice on refining this regex to properly exclude IPs with leading zeros while still validating correct IP formats would be greatly appreciated. I'm using Go version 1.18.1 and the `regexp` package for pattern matching. I'm coming from a different tech stack and learning Go. Thanks for your help in advance!