CSharp · Console
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
var text = "fakeLogOpen(/dev/log_crash, O_WRONLY) failed ";
var androidErrorRegex = new Regex (@"
^
( # start optional path followed by `:`
(?<path>
(?<file>.+[\\/][^:\(]+)
(
([:](?<line>\d+))
|
(\((?<line>\d+)\))
)?
)
\s*
:
)?
( # optional warning|error:
\s*
(?<level>(warning|error)[^:]*)\s*
:
)?
\s*
(?<message>.*)
$
", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);
Console.WriteLine("IsMatch: " + androidErrorRegex.IsMatch(text));
var m = androidErrorRegex.Match(text);
Console.WriteLine("path: {0}", m.Groups ["path"].Value);
Console.WriteLine("level: {0}", m.Groups ["level"].Value);
Console.WriteLine("message: {0}", m.Groups ["message"].Value);
}
}