送分了,求一简单的正则表达式! 从诸如"A~B=C"中提取:A,B,C,A、B可以为Null,本人不会正则表达式,希望贴出代码,测试通过立即结贴 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的abc各是什么?字母?数字?还是别的什么。 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;} to:mobydick,非常感谢上次的帮助是double或int型的数字,注意前后都有可能为空(null) 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;} to q_po_o:谢谢你的帮助,但目前还没有实现我的要求:0~100.25=23就解析不出来了,我还要求能解析出~100.25=23.5及10001~=35.5这种格式,非常感谢 这次看看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; 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 够火热,借宝地一用。到时楼主可以去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中的 [求助]winform打印的源码~谢谢。 外部应用程序也不能访问ie中的跨域iframe? 关于引用类型的转换 怎么使gridview里的一个单元格可编辑,其他的单元格都不可编辑阿? 怎样定义OracleParameter的DbType 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。 当一个object类型的值为NULL时,怎样将他强制转换为INT型 如何一台电脑控制3台电视的输出情况 如何将显示的数据以excel形式保存? 截取IP的包 怎么实现界面的换肤 C# 表格 ~问题~
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;
}
是double或int型的数字,注意前后都有可能为空(null)
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;
}
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;
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
在文章内容里面有ubb代码,还有非ubb代码
http://www.domain.com/images/02.gif,现在我要把所有非ubb代码替换成ubb代码。图片类型包括jpg、gif、bmp。其中还可能有flash。但是不知道该怎么匹配http://www.domain.com/images/02.gif之类的代码,请各位高手帮忙!图片可以是任何网站的,匹配的图片不包括ubb中的