首页  编辑  

正则动态替换字符串

Tags: /C#/字符串处理/正则表达式/   Date Created:

using System . Text . RegularExpressions;

string str = textBox1 . Text;

MatchCollection vMatches = Regex . Matches(str, @">(\[m.v\])</" );

for ( int i = vMatches . Count - 1 ; i >= 0 ; i -- )

{

   str = str . Remove(vMatches[i] . Groups[ 1 ] . Index,

       vMatches[i] . Groups[ 1 ] . Value . Length);

   str = str . Insert(vMatches[i] . Groups[ 1 ] . Index, i . ToString());

}

textBox2 . Text = str;