using System.Text.RegularExpressions; static void ExtractIpDemo() { string url = "192.125.35.48\d\subfolder\bsubfolder\cfolder\d.txt"; string ipValue = ExtractIPAddressFromUrl(url); Console.WriteLine(ipValue); } static string ExtractIPAddressFromUrl(string remoteAddress) { string ipHost = string.Empty; var match = Regex.Match(remoteAddress, @"(d{1,3}.d{1,3}.d{1,3}.d{1,3})"); if (match.Success) { ipHost = match.Captures[0].Value; } return ipHost; }