using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^((?:\d+\.){3}\d+).*?\[([^]]*)\].*?""([^""]*)""\s*(\d+)\s*(\d+)\s*""-""\s*""([^""]*)""$";
string substitution = @"$1 $2 $3 $4 $5 $6";
string input = @"123.4.5.1 - - [03/Sep/2013:18:38:48 -0600] ""GET /products/car/ HTTP/1.1"" 200 3327 ""-"" ""Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36""
123.4.5.6 - - [03/Sep/2013:18:38:58 -0600] ""GET /jobs/ HTTP/1.1"" 500 821 ""-"" ""Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0""";
RegexOptions options = RegexOptions.Multiline;
Regex regex = new Regex(pattern, options);
string result = regex.Replace(input, substitution);
}
}
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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx