preg_replace_callback('/((?:https?|ftp):\/\/(?:www\.)?(?:[a-zA-Z0-9][a-zA-Z0-9\-]*\.)?[a-zA-Z0-9][a-zA-Z0-9\-]*(?:\.[a-zA-Z0-9]+)+(?:\:[0-9]*)?(?:\/[^\x{2e80}-\x{9fff}\s<\'\"“”‘’]*)?)/u',getContentUrl, $save['content'])
将上面的php代码转成.net的,.net中是用这个public static string Replace(string input, string pattern, MatchEvaluator evaluator, RegexOptions options);,就是正则表达式部分,求精通这两门语言的高手!

解决方案 »

  1.   

    精通PHT和.NET的不多你最好把PHP的代码想要干什么先解释一下很多人可以把它用C#写出来
      

  2.   

    也在学习php,但是正则了解得不多,就是想将字符串里的url提取出来,网上也找了几个,试了都不行。
      

  3.   


    Regex.Replace($save['content'],@"(?:https?|ftp)://(?:www\.)?(?:[a-zA-Z0-9][a-zA-Z0-9\-]*\.)?[a-zA-Z0-9][a-zA-Z0-9\-]*(?:\.[a-zA-Z0-9]+)+(?:\:[0-9]*)?(?:/[^\x{2e80}-\x{9fff}\s<\'\"“”‘’]*)?",
    m=>{ /*getContentUrl 方法处理逻辑写在这里 */});
      

  4.   


    Regex.Replace($save['content'],@"(?:https?|ftp)://(?:www\.)?(?:[a-zA-Z0-9][a-zA-Z0-9\-]*\.)?[a-zA-Z0-9][a-zA-Z0-9\-]*(?:\.[a-zA-Z0-9]+)+(?:\:[0-9]*)?(?:/[^\x{2e80}-\x{9fff}\s<'““"““‘’]*)?",
    m=>{ /*getContentUrl 方法处理逻辑写在这里 */});
      

  5.   

    '(?=http|/)(?![~#]|ftp)[^']*'
    (?=http|/) 限制必须以http或/开头
    (?![~#]|ftp) 限制不以~、#或ftp开头
      

  6.   

    Regex reg = new Regex(@"((http|https|ftp):(\/\/|\\\\)){0,}((\w)+[.]{1,}([\~]*))(.*[\x00-\xff])")
      

  7.   

    直接拷贝过去,.net报异常:十六进制位数不足