using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\\([a-zA-Z]+ *|.|\n)";
string input = @"\documentclass {book}
\usepackage{a}
\begin {document}
\chapter*{This is the title of a index-absent chapter}
\I'll try to do some actual \LaTeX\ text to se\footnote {This is text in a footnote.} how it will be matched.
\chapter{This is {\bf another} chapter title}
You have to be carefull with accents, like ``Espa\~nol''
and active characters (characters like the quotes above
or the newline character, which act by themselves as a
command).\
You have to be carefull also with comments (beginning with
the percentage char) % this is one comment.
And of course you'll loose al your math, as in
$e^{i\pi} + 1 = 0$.
\end{document}
";
foreach (Match m in Regex.Matches(input, pattern))
{
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