****正则表达式(50分) 源字符串:p3a0b0?kw=%e5%bc%a0问题:我想匹配出?kw前面的a0,而不是kw后面的a0,正则应该怎么写(注意上面p、a、b、?kw=后面的参数都会发生变化)要求:用零宽断言.而不是简单的用p(\d+)a(\d+)这种方式 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以先截取?kw前的 再去匹配a0 MatchCollection allMatchResults = null;try { Regex regexObj = new Regex(@"a\d+(?=.*kw)"); allMatchResults = regexObj.Matches("a\d+(?=.*kw)"); if (allMatchResults.Count > 0) { // Access individual matches using allMatchResults.Item[] } else { // Match attempt failed } } catch (ArgumentException ex) { // Syntax error in the regular expression} 搞错了MatchCollection allMatchResults = null;try { Regex regexObj = new Regex(@"a\d+(?=.*kw)"); allMatchResults = regexObj.Matches("p3a0b0?kw=%e5%bc%a0"); if (allMatchResults.Count > 0) { // Access individual matches using allMatchResults.Item[] } else { // Match attempt failed } } catch (ArgumentException ex) { // Syntax error in the regular expression} 我可以用程序控制ObjectDataSource1中的TableAdapter的SelectCommand吗,谢了 查询结果要求类似于携程酒店查询的展示方式,asp.net下应该用什么控件!?在线急等,高分求解,谢谢! 多个usercontrol调用ajax中返回dataset问题 使用触发器的问题!!! 关于yahoo的编码问题 刚学C#,请问个菜鸟问题? 请问大家一般用什么动态包含文件呢?iframe还是include! 在线求解,一个简单查询问题! 这个网络项目如何构架部署?(顶有分) 如何获得所有页面变量传递? 后缀名为sql的数据文件怎么用 关于asp.net图片的上传和预览
try {
Regex regexObj = new Regex(@"a\d+(?=.*kw)");
allMatchResults = regexObj.Matches("a\d+(?=.*kw)");
if (allMatchResults.Count > 0) {
// Access individual matches using allMatchResults.Item[]
} else {
// Match attempt failed
}
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}
try {
Regex regexObj = new Regex(@"a\d+(?=.*kw)");
allMatchResults = regexObj.Matches("p3a0b0?kw=%e5%bc%a0");
if (allMatchResults.Count > 0) {
// Access individual matches using allMatchResults.Item[]
} else {
// Match attempt failed
}
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}