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);,就是正则表达式部分,求精通这两门语言的高手!
将上面的php代码转成.net的,.net中是用这个public static string Replace(string input, string pattern, MatchEvaluator evaluator, RegexOptions options);,就是正则表达式部分,求精通这两门语言的高手!
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 方法处理逻辑写在这里 */});
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 方法处理逻辑写在这里 */});
(?=http|/) 限制必须以http或/开头
(?![~#]|ftp) 限制不以~、#或ftp开头