2007-2009 广州城市 白云区 某某街
我想取"白云区"怎么用正则取???也有可能:
2007-2009 广州城市 白云区  某某街
           

解决方案 »

  1.   

    2007-2009 广州城市 某某地方 某某街 不一定有区,,两边是" "那是一定的
      

  2.   

    string str = "2007-2009 广州城市 某某地方 某某街 ";
    string[] strArr = str.split(" ")string test = strArr[2].ToString();
      

  3.   

    (?> )\s*(\w{2,})\s*((?= )
    那么这样
      

  4.   


    需求不明确,描述不清晰想写出正确的正则也是万万不能的提取相关的正则,一定要描述清楚规则,如何唯一定位你要的数据,如何区别相似的数据
    光是两边都有“ ”并不是唯一定位该数据的规则,因为“广州城市”两边也有“ ”根据你目前的举例来看,只能写出这样的正则
    MatchCollection mc = Regex.Matches(yourStr, @"(?i)(?<!\d(?:&nbsp;)*)(?<=&nbsp;\s*)(?:(?!\s*&nbsp;).)+(?=\s*&nbsp;)");
    foreach (Match m in mc)
    {
        richTextBox2.Text += m.Value + "\n";
    }