Regex Doesn't Capture All Valid IP Addresses in C# - Overlooking Edge Cases
I'm stuck trying to I've tried everything I can think of but I've looked through the documentation and I'm still confused about I'm working on a C# application where I need to validate and extract valid IPv4 addresses from a text file..... My current regex pattern is `\b(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\b`, but I'm noticing that it fails to capture some addresses due to certain edge cases. For instance, addresses like '192.168.01.1' are not being matched, and I need them to be included as valid. I've tried using `RegexOptions.IgnoreCase` when compiling the regex, but that didn't help. Here's a snippet of the code I'm using: ```csharp using System; using System.IO; using System.Text.RegularExpressions; class Program { static void Main() { string pattern = "\\b(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\\b"; Regex regex = new Regex(pattern); foreach (var line in File.ReadLines("ipAddresses.txt")) { Match match = regex.Match(line); if (match.Success) { Console.WriteLine("Found IP: " + match.Value); } } } } ``` When I run the program with a file containing various IP addresses, it simply skips over valid ones that have leading zeros, throwing me off. What adjustments should I make to my regex to ensure it captures those edge cases correctly? Also, are there any performance considerations I should be aware of with this regex pattern, especially if the file contains a large number of lines? This is part of a larger CLI tool I'm building. Any help would be greatly appreciated! I'm on Linux using the latest version of C#. Any examples would be super helpful. Any ideas how to fix this?