日期:2014-05-19  浏览次数:20694 次

请教一个正则表达式的问题,在“集安(11601500)”如何提取站明和站号?
字符串是“集安(11601500)”
站名:集安
站号:11601500

我是这样写的,但取出的结果有些问题:   "^(? <stnm> .+)(?:(? <stcd> \d{8})) "
请各位帮我修改一些,非常感谢!!

------解决方案--------------------
按楼主意思,^(? <stnm> [^(]+)\((?:(? <stcd> \d{8}))\)
------解决方案--------------------
Regex reg = new Regex(@ "^(? <stnm> [\s\S]*)(\()(? <stcd> \d{8})(\)) ");
Match mr = reg.Match(@ "集安(11601500) ");
if (mr.Success)
{
this.TextBox1.Text = mr.Groups[ "stnm "].Value + "::: " + mr.Groups[ "stcd "].Value;
}

---------------------------------------------
EMail:bdbox@163.com 请给我一个与您交流的机会!
------解决方案--------------------
或者这样
^(? <stnm> [^(]+).+?((? <=\()(? <stcd> \d+?(?=\))))
------解决方案--------------------
Regex re4 = new Regex(@ "^(? <name> [^(]+)\((? <num> [^)]+) ");
Match rem4 = re4.Match(@ "集安(11601500) ");
Response.Write( " </br> " + rem4.Groups[ "name "]);
Response.Write( " </br> " + rem4.Groups[ "num "]);