相关疑难解决方法(0)

Regex.Replace中的MatchEvaluator如何工作?

这是输入字符串23x * y34x2.我希望" * "在每个数字之后插入(由空格包围的星形)后跟字母,并在每个字母后跟数字.所以我的输入字符串看起来像这样:23 * x * y * 34 * x * 2.

这是完成这项工作的正则表达式:@"\d(?=[a-z])|[a-z](?=\d)".这是我写的插入的函数" * ".

Regex reg = new Regex(@"\d(?=[a-z])|[a-z](?=\d)");   
MatchCollection matchC;
matchC = reg.Matches(input);
int ii = 1;
foreach (Match element in matchC)//foreach match I will find the index of that match
{
    input = input.Insert(element.Index + ii, " * ");//since I' am inserting " * " ( 3 characters )
    ii += 3;                                        //I must …
Run Code Online (Sandbox Code Playgroud)

.net c# regex replace matchevaluator

43
推荐指数
1
解决办法
3万
查看次数

标签 统计

.net ×1

c# ×1

matchevaluator ×1

regex ×1

replace ×1