http://stackoverflow.com/questions/11507239/linq-query-result-with-string-manipulation-and-regex
string source = @"\354\202\254\354\232\251\354\236\220\354\203\201\354\204" + @"\270\354\240\225\353\263\264\354\236\205\353\240\245"; var r = new Regex(@"(\\[0-8]{3})*"); var m = r.Match(source); string res = ""; foreach (var x in m.Groups) { byte[] bytes = x.ToString().Split (new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries) .Select (s => (byte)Convert.ToInt32 (s, 8)) .ToArray (); string result = System.Text.Encoding.UTF8.GetString (bytes); res += result; } Debug.Log (res);
これだとカッコ内もされる
if (GUILayout.Button("TEST")) { string source = @"うん\354\202\254\354\232\251\354\236\220\354\203\201\354\204" + @"\270\354\240\225\353\263\264\354\236\205\353\240\245" + @"あ\354\202\254\354\232\251\354\236\220\354\203\201\354\204" + @"\270\354\240\225\353\263\264\354\236\205\353\240\245"; var regex = new Regex(@"(?<text>(\\[0-8]{3})*)"); string output = regex.Replace(source, new MatchEvaluator(RegexReadTerm)); Debug.Log (output); } } private string RegexReadTerm(Match m) { byte[] bytes = m.Groups["text"].ToString().Split (new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries) .Select (s => (byte)Convert.ToInt32 (s, 8)) .ToArray (); string result = System.Text.Encoding.UTF8.GetString (bytes); // The term name is captured in the first group return