C# 正则表达式 提取字符

2025-02-26 18:43:42
推荐回答(3个)
回答1:

   string str = "GetLan.translate('TypeA', 'Str2','无效');";
            MatchCollection mtc = Regex.Matches(str, @"translate\('([\w\w]+)'([\w\W].+?)'([\w\W].+?)'([\w\W].+?)([\w\W].+?)'\)");
            foreach (Match item in mtc)
            {
                Console.WriteLine(item.Groups[1].ToString() + "       " + item.Groups[3].ToString() + "       " + item.Groups[5].ToString());
            }

回答2:

(?i)(?<=GetLan\.translate\(\')([^']*)',\s*'([^']*)','([^']*)'\);


回答3:

‘\w+’就行了。