using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^
(?# Piece Placement Section)(?<PiecePlacement>((?<RankItem>[pnbrqkPNBRQK1-8]{1,8})\/?){8})
(?# Section Separator)\s+
(?# Side To Move Section) (?<SideToMove>b|w)
(?# Section Separator)\s+
(?# Castling Ability) (?<Castling>-|K?Q?k?q)
(?# Section Separator)\s+
(?# En passant) (?<EnPassant>-|[a-h][3-6])
(?# Section Separator)\s+
(?# Half Move Clock) (?<HalfMoveClock>\d+)
(?# Section Separator)\s+
(?# Full Move Number) (?<FullMoveNumber>\d+)
\s*
$";
string input = @"rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2";
RegexOptions options = RegexOptions.IgnorePatternWhitespace;
Match m = Regex.Match(input, pattern, options);
Console.WriteLine("'{0}' found at index {1}", m.Value, m.Index);
}
}
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