Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 来自名称的正则表达式特定单词_C#_Regex_Validation_Tableau Api_Regexp Replace - Fatal编程技术网

C# 来自名称的正则表达式特定单词

C# 来自名称的正则表达式特定单词,c#,regex,validation,tableau-api,regexp-replace,C#,Regex,Validation,Tableau Api,Regexp Replace,例如,我试图找出用户在名称和关系中输入的格式错误的名称的正则表达式作为一个值 [约瑟夫·乔斯塔之子]=>s/o。约瑟夫乔斯塔 问题是,由于没有验证,用户输入了不同的变体,如 s/o,s/,s/Joseph,等 到目前为止我已经做到了 ^(s\/o.)(S\/o.)(s\/o)(S\/o)(s\/)(S\/)\w+ 关系在开头或开头,后面是名称 还有3例是女儿/o、妻子/o、父亲/o。 我想知道相应的正则表达式以过滤掉关系前缀 提前谢谢你也许可以从这样的事情开始 string foo = &qu

例如,我试图找出用户在名称和关系中输入的格式错误的名称的正则表达式作为一个值

[约瑟夫·乔斯塔之子]=>s/o。约瑟夫乔斯塔

问题是,由于没有验证,用户输入了不同的变体,如

s/o,s/,s/Joseph,等

到目前为止我已经做到了

^(s\/o.)(S\/o.)(s\/o)(S\/o)(s\/)(S\/)\w+
关系在开头或开头,后面是名称 还有3例是女儿/o、妻子/o、父亲/o。 我想知道相应的正则表达式以过滤掉关系前缀


提前谢谢你

也许可以从这样的事情开始

string foo = "s/o. Joseph Joestar";

// Look (and capture) for SDWF followed by "/" and 
// EITHER "o" and maybe "." and maybe a white space
// OR we look ahead (?=  ) and see a Upper wordchar followeed by lower word chars.
//   look ahead because we do not want to have anything to do with this when replacing
string bar = Regex.Replace(foo, @"^([sSdDwWfF])/(o\.?\s?|(?=[A-Z]\w+))", match =>
{
    string relation = match.Groups[1].Value.ToUpper() switch
    {
        "S" => "Son of",
        "D" => "Daughter of",
        "F" => "Father of",
        "W" => "Wife of",
        _ => throw new Exception("Oops")
    };
    return $"{relation} ";
});


你的问题是什么?