日期:2014-05-17  浏览次数:20633 次

跪求!!正则表达式!!
从网页上获取的string如下,

HTML code


2012-08-31 07:01 《公司业绩》华电国际(01071.HK)中期纯利2.8亿人民币 增长170%
2012-08-31 06:55 《公司业绩》四川成渝(00107.HK)中期纯利6.5亿人民币 增14%
2012-08-31 06:50 《公司业绩》长城科技(00074.HK)全年利润2043万人民币 跌83%
2012-08-31 07:00 《公司业绩》中信证券(06030.HK)中期纯利22.5亿人民币 跌24%





现在要求:
1、获取股票代码,代码全是港股的,这个简单,已经搞定,;
2、简单判断一下文字里对业绩的表述,基本上业绩的格式也是固定的,就是:纯利/利润XXX货币单位,增/跌百分之几;

如果是增长的,返回符号“+”;
如果是减少的,返回符号“-”;

请问高手们,该怎么写?会不会因为汉字的缘故难以判断?




------解决方案--------------------
C# code
string tempStr = @"2012-08-31 07:01 《公司业绩》华电国际(01071.HK)中期纯利2.8亿人民币 增长170%
2012-08-31 06:55 《公司业绩》四川成渝(00107.HK)中期纯利6.5亿人民币 增14%
2012-08-31 06:50 《公司业绩》长城科技(00074.HK)全年利润2043万人民币 跌83%
2012-08-31 07:00 《公司业绩》中信证券(06030.HK)中期纯利22.5亿人民币 跌24%";
                string pattern = @"(?i)\(([^()]+?)\)\S+?\s+?([\u4e00-\u9fa5])";
                var result = Regex.Matches(tempStr, pattern).Cast<Match>().Select(a => new { code=a.Groups[1].Value,state=a.Groups[2].Value.Equals("增")?"+":"-"});
                /*
                 * +        [0]    { code = "01071.HK", state = "+" }    <Anonymous Type>
                    +        [1]    { code = "00107.HK", state = "+" }    <Anonymous Type>
                    +        [2]    { code = "00074.HK", state = "-" }    <Anonymous Type>
                    +        [3]    { code = "06030.HK", state = "-" }    <Anonymous Type>

                 */