string text = "/08492184982/abc.gif";  
Regex regex = new Regex(@"\/([.^\/]+)\/abc\.gif$", RegexOptions.IgnoreCase);  
MatchCollection matchCollection = regex.Matches("/08492184982/abc.gif");  
if (matchCollection.Count == 1){
    string redfont = matchCollection[0].Groups[0].Value;
    Console.WriteLine("红色的字是:" + redfont );  
}
这个一直匹配不到红色的字,请大家帮忙

解决方案 »

  1.   

                string text = "/08492184982/abc.gif";
                var val = Regex.Match(text, "/(.*?)/abc.gif").Groups[1].Value;
      

  2.   

    转换思路咯:var val2 = text.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[0];
      

  3.   

    string text = "/08492184982/abc.gif";            
     var val = Regex.Match(text, "/(.*?)/abc.gif").Groups[1].Value;这个没有排除 / 这个符号
      

  4.   

    如果是这样的情况 /sadfsfs/fsadfs/imsi.gif
      

  5.   

    string text = "/08492184982/abc.gif";            
     var val = Regex.Match(text, "/([^/\\]+?)/abc.gif").Groups[1].Value; /sadfsfs/fsadfs/imsi.gif    这一种情况,和上面的模式一样。
      

  6.   

    string text = "/08492184982/abc.gif";  
    Regex regex = new Regex(@"\/([^\/]+)\/abc\.gif$", RegexOptions.IgnoreCase);  
    MatchCollection matchCollection = regex.Matches("/08492184982/abc.gif");  
    if (matchCollection.Count == 1){
        string redfont = matchCollection[0].Groups[0].Value;
        Console.WriteLine("红色的字是:" + redfont );  
    }
    这个一直匹配不到红色的字,请大家帮忙 
      

  7.   

    int _tmain(int argc, _TCHAR* argv[])
    { string seq = "string text = \"/08492184982/abc.gif";
    regex rgx("\\d+(?=/)"); regex_iterator<string::iterator> it(seq.begin(),seq.end(),rgx);
    regex_iterator<string::iterator> end;

    short cnt=0;
    vector<int> v_int;
    while (it!=end)
    {
    cout<<++cnt<<"\t:";
    v_int.push_back(strtol(it->str().c_str(),NULL,10));
    cout<<it++->str()<<endl;

    }

    }
      

  8.   

      string str = "/08492184982/abc.gif";
                str = Regex.Match(str, @"(?is)(?<=/)[^/]+(?=/[\w_]+\.[a-z0-9]+/?$)").Value;