正则表达式,求最后一个冒号(可能没有)到第一个句号之间的内容

2025-04-14 02:00:51
推荐回答(2个)
回答1:

C#版本:

        static void Main(string[] args)
        {
            string all = @"任意字符:任意字符:需要的.任意字符.任意字符";
            //string all = @"需要的.任意字符.任意字符";
            Match m = Regex.Match(all, @"\w+?(?=\.)");
            Console.WriteLine(m);
            Console.ReadLine();
        }

回答2:

(?<=(:))((?!:).)*(。|$)
这样试试