After much frustration with not getting std::regex or boost::regex working under Windows, but working elsewhere, I decided to try my luck with C# in regards to getting my code to work.Basically I'm trying to parse in a list of instructions in a certain format for a game. My C# implementation doesn't work at all.
Here's a sample of the input file:
Code:
LANGUAGE {English/ANSI}
LEVEL6 {}
ITEMTOT {124}
INAM1 {dagger}
IDES1 {a dagger}
ISTT1 {15 10 0 1 3 1 0 0 0 1 0 0 0 0 0 0}
IEFF1 {}
And the code itself:
Code:
using System;
using System.IO;
using System.Text.RegularExpressions;
namespace MyGame
{
static class Program
{
static bool parseScript(string filename)
{
StreamReader sr = new StreamReader(filename);
Regex labelSyntax = new Regex(@"(\w+)([0-9]*)\s+\{(.*)\}");
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
MatchCollection m = labelSyntax.Matches(line);
Console.WriteLine("{0}", m.Count);
if (m.Count > 0)
{
switch (m[0].Value)
{
case "LANGUAGE":
Console.WriteLine("Locale set to {0}", m[2].Value);
break;
default:
break;
}
}
}
sr.Close();
return true;
}
static int Main(string[] args)
{
parseScript(args[0]);
return 0;
}
}
}
At this point I'm wondering if it's simply invalid regex. I'm trying to capture the label, the number at the end separately (if any), and what's between the curly braces, if anything.