从诸如"A~B=C"中提取:A,B,C,A、B可以为Null,本人不会正则表达式,希望贴出代码,测试通过立即结贴

解决方案 »

  1.   

    你的abc各是什么?字母?数字?还是别的什么。
      

  2.   

    string content = @"qre~B222=C3434";
    string  strValue = "";
    string strRegex = @"(?<A>\w*)~(?<B>\w*)=(?<C>\w*)";Regex re = new Regex(strRegex, RegexOptions.IgnoreCase | RegexOptions.Multiline);foreach (Match m in re.Matches(content))
    {
    strValue += "A:" + m.Groups["A"].Value+"B:" + m.Groups["B"].Value+"C:" + m.Groups["C"].Value;
    }
      

  3.   

    to:mobydick,非常感谢上次的帮助
    是double或int型的数字,注意前后都有可能为空(null)
      

  4.   

    string content = @"qre~B222=C3434";
    string  strValue = "";
    string strRegex = @"(?<A>^(-?\\d*)(\\.\\d+)?$)~(?<B>^(-?\\d*)(\\.\\d+)?$*)=(?<C>^(-?\\d*)(\\.\\d+)?$*)";Regex re = new Regex(strRegex, RegexOptions.IgnoreCase | RegexOptions.Multiline);foreach (Match m in re.Matches(content))
    {
    strValue += "A:" + m.Groups["A"].Value+"B:" + m.Groups["B"].Value+"C:" + m.Groups["C"].Value;
    }
      

  5.   

    to q_po_o:谢谢你的帮助,但目前还没有实现我的要求:0~100.25=23就解析不出来了,我还要求能解析出~100.25=23.5及10001~=35.5这种格式,非常感谢
      

  6.   

    这次看看
    string content = @"0~100.25=23";
    string  strValue = "";
    string strRegex = "(?<A>(-?\\d*)(\\.\\d+)?)~(?<B>(-?\\d*)(\\.\\d+)?)=(?<C>(-?\\d*)(\\.\\d+)?)";Regex re = new Regex(strRegex, RegexOptions.IgnoreCase | RegexOptions.Multiline);foreach (Match m in re.Matches(content))
    {
    strValue += "A:" + m.Groups["A"].Value+"B:" + m.Groups["B"].Value+"C:" + m.Groups["C"].Value;
    }
    TextBox1.Text = strValue;
      

  7.   

    string regexStr = "(?<A>[0-9]+(\\.[0-9]+)?)?~(?<B>[0-9]+(\\.[0-9]+)?)?=(?<C>[0-9]+(\\.[0-9]+)?)?";
    MatchCollection mc = Regex.Matches(yourStr, regexStr);
    foreach(Match m in mc)
    {
        m.Groups["A"].Value;//
        m.Groups["B"].Value;//
        m.Groups["C"].Value;//
    }
    //Value有可能为String.Empty
      

  8.   

    够火热,借宝地一用。到时楼主可以去http://community.csdn.net/Expert/topic/5029/5029108.xml?temp=.225506领分我也有一正则表达式问题:
    在文章内容里面有ubb代码,还有非ubb代码
    http://www.domain.com/images/02.gif,现在我要把所有非ubb代码替换成ubb代码。图片类型包括jpg、gif、bmp。其中还可能有flash。但是不知道该怎么匹配http://www.domain.com/images/02.gif之类的代码,请各位高手帮忙!图片可以是任何网站的,匹配的图片不包括ubb中的