我正在为已请求它的游戏服务器开发一个kill feed类型程序。
在大多数情况下,除了清理以下字符串的最简单方法之外,一切都非常简单:
name1[1234567/12345678901234567] was killed by name2[12345/12345678901234567]
要注意事项:
非常感谢任何帮助我指明正确方向的帮助!
答案 0 :(得分:1)
您可以使用这样的正则表达式:
(?<name1>.*)\[(.*\/)?(?<val1>.*)\] was killed by (?<name2>.*)\[(.*\/)?(?<val2>.*)\]
请参阅regex101
成功时,Regex.Match
将返回2个组:val1
和val2
,其中包含值。
示例代码
var pattern = @"(?<name1>.*)\[(.*\/)?(?<val1>.*)\] was killed by (?<name2>.*)\[(.*\/)?(?<val2>.*)\]";
var input = @"name1[1234567/12345678901234567] was killed by name2[12345/12345678901234567]";
var match = Regex.Match(input, pattern);
if (match.Success)
Console.WriteLine("1st value = {0}, 2nd value = {1}", match.Groups["val1"], match.Groups["val2"]);
<强>输出强>
第一个值= 12345678901234567,第二个值= 12345678901234567