13.04.2024 13:23 C#
Пошук тексту по шаблону
Є текст в якому є вставки типу{{111}}. Наприклад: "text text {{111}} text {{112}} text"using System.Text.RegularExpressions;
string pattern = @"\{\{(.*?)\}\}";
foreach (Match match in Regex.Matches("text text {{111}} text {{112}} text", pattern))
if (match.Success && match.Groups.Count > 0)
{
string text = match.Groups[1].Value;
Console.WriteLine(text);
}string sentence = "Employee name is [{#john#}], works for [{#ABC BANK#}], [{#Houston#}]";
string pattern = @"\[\{\#(.*?)\#\}\]";
foreach (Match match in Regex.Matches(sentence, pattern))
{
if (match.Success && match.Groups.Count > 0)
{
var text = match.Groups[1].Value;
Console.WriteLine(text);
}
}
Console.ReadLine();© accounting.org.ua - 2025