I am getting results from regex matches that I don't understand. In all cases, I'd expect the program below to output the same thing for Foo that it does for Bar, and to match exactly 6 characters every time.
ironmeta Test<char, char>
{
Foo = /[^\r\n]+/ -> { return new string(_IM_Result.Inputs.ToArray()); };
Bar = (~('\r' | '\n').)+ -> { return new string(_IM_Result.Inputs.ToArray()); };
}
class Program
{
static void PrintMatch(IronMeta.Matcher.MatchResult<char, char> m)
{
Console.WriteLine($"{m.Success} {m.NextIndex}");
if (m.Success)
{
Console.WriteLine(string.Join(',', m.Results.Select(c => (int)c)));
}
}
static void Compare(string s)
{
var p1 = new Test();
var m1 = p1.GetMatch(s, p1.Foo);
Console.WriteLine("foo:");
PrintMatch(m1);
var p2 = new Test();
var m2 = p2.GetMatch(s, p2.Bar);
Console.WriteLine("bar:");
PrintMatch(m2);
}
static void Main(string[] args)
{
Compare("Hello!");
Compare("Hello!\n");
Compare("Hello!\nWorld!\n");
}
}
foo:
True 6
72,101,108,108,111,33
bar:
True 6
72,101,108,108,111,33
foo:
True 7
72,101,108,108,111,33,10
bar:
True 6
72,101,108,108,111,33
foo:
False -1
bar:
True 6
72,101,108,108,111,33