using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\\RequirePackage(\[([^][]*)\])?([^{]*){([^{}]*)}.*(?:\n\s*\[([^][]*)])?";
string input = @"\RequirePackage[
top = 2.5cm,
bottom = 2.5cm,
left = 2.5cm,
right = 2.5cm,
marginparwidth = 2cm,
marginparsep = 2mm,
heightrounded
]{geometry}%
[2020-01-02]
\RequirePackage{tocbasic}
\RequirePackage[svgnames]%
{xcolor}%
[2023/11/15]
\RequirePackage[raggedright]% OK?
{titlesec}
\RequirePackage{xcolor}%
[2022/06/12]
\RequirePackage{hyperref}% To load after titlesec!
[2023-02-07]";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(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