正则表达式识别西里尔单词

本文关键字:单词 识别 正则表达式 | 更新日期: 2023-09-27 18:17:00

我有字符串test (strange) test - test - копія (121321)我需要识别копія

附近括号中的数字
Regex rgx = new Regex(@"-'s'копія's'(('d+)')");
Match match = rgx.Match(newDoc.ConsignmentDocumentData.Content.DocumentName);

但是会抛出异常

{"解析'",' s 'копія' ' ((' d +) ') ' "- 未被认可的esc序列到' _。"}

如何修复?

正则表达式识别西里尔单词

去掉к前的反斜杠:

@"-'s*копія's*'(('d+)')"

参见regex演示。

c#演示:

var s = "test (strange) test - test - копія (121321)";
var pattern = @"-'s*копія's*'(('d+)')";
var result = Regex.Match(s, pattern);
if (result.Success)
    Console.WriteLine(result.Groups[1].Value); // => 121321