mightguy mightguy - 1 month ago 8
C# Question

Error CS1525: Unexpected symbol `Match'

I'm trying to compile a code but the compiler give me this error

This is my code

https://ideone.com/2whEtn

using System;
using System.IO;
using System.Text.RegularExpressions;

class Program
{
static void Main()
{
string strpath = File.ReadAllText(@"C:\Users\mistery\Desktop\regex.txt");
i=0
Match match = Regex.Match(strpath, $"(?<=\\d{i} +(\\w)*.*?\\d) +(\\d+)"), RegexOptions.IgnoreCase);
}
}

Answer

You have an invalid ")" between the "pattern" and "options" parameters

String pattern = $"?<=\\d +(\\w)*.*?\\d) +(\\d+)"; // interpolation??
Match match = Regex.Match(strpath, pattern, RegexOptions.IgnoreCase);

$ is for the new string interpolation in C# 6