string data = "some text *text* ok *text* hello **world*";
// Надо, чтобы стало "some text **text** ok **text** hello ***world**"
string pattern = @"(?:[*])([^*].*?)(?:[*])";
MatchCollection matches = new Regex(pattern).Matches(data);
if (matches.Count > 0)
{
foreach (Match match in matches)
{
Console.WriteLine(match);
data = Regex.Replace(data, pattern, "*" + match + "*");
}
}
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
string data = "some text *text* ok *text* hello **world*";
// Надо, чтобы стало "some text **text** ok **text** hello ***world**"
string pattern = @"(?:[*])([^*].*?)(?:[*])";
var regex = new Regex(pattern);
var result = regex.Replace(data, m => $"*{m.Value}*");
Console.WriteLine(result);
}
}