有个xml文件
有大量的<A_B>aaaaaa</A_B> 
我想用正则把所有   
<A_B> 中间的部分替换掉 
该怎么写呢? 谢谢 

解决方案 »

  1.   

    用Regex.Replace()
    参考
    // This code example demonstrates the System.Text.Regular-
    // Expressions.Regex.Replace(String, String) method.using System;
    using System.Text.RegularExpressions;class Sample 
    {
        public static void Main() 
        {
    // Create a regular expression that matches a series of one 
    // or more white spaces.
        string pattern = @"\s+";
        Regex rgx = new Regex(pattern);// Declare a string consisting of text and white spaces.
        string inputStr = "a   b   c   d";// Replace runs of white space in the input string with a
    // comma and a blank.
        string outputStr = rgx.Replace(inputStr, ", ");// Display the resulting string.
        Console.WriteLine("Pattern:       \"{0}\"", pattern);
        Console.WriteLine("Input string:  \"{0}\"", inputStr);
        Console.WriteLine("Output string: \"{0}\"", outputStr);
        }
    }
    /*
    This code example produces the following results:Pattern:       "\s+"
    Input string:  "a   b   c   d"
    Output string: "a, b, c, d"*/
      

  2.   

    Regex 可以用(?<=<A_B>).*(?=</A_B>)
      

  3.   

    正则好像不行吧 。我感觉 用 xmldocument 读取 节点修改比较好啊
      

  4.   

    下载PilotEdit 2.7, http://topic.csdn.net/u/20090723/07/33b39399-81ad-4fb1-a4a2-78509d2161a3.html用下面的正则表达式查找替换:
    查找:<A_B>[]*</A_B>
    替换为:%01%03
    假设原始文件为:
    有个xml文件
    有大量的 <A_B>aaaaaa </A_B>
    我想用正则把所有 
    <A_B> 中间的部分替换掉
    该怎么写呢? 谢谢

    将被转换为:
    有个xml文件
    有大量的 <A_B></A_B>
    我想用正则把所有 
    <A_B> 中间的部分替换掉
    该怎么写呢? 谢谢