C#版本:
static void Main(string[] args) { string all = @"任意字符:任意字符:需要的.任意字符.任意字符"; //string all = @"需要的.任意字符.任意字符"; Match m = Regex.Match(all, @"\w+?(?=\.)"); Console.WriteLine(m); Console.ReadLine(); }
(?<=(:))((?!:).)*(。|$)这样试试