C# 来自名称的正则表达式特定单词
例如,我试图找出用户在名称和关系中输入的格式错误的名称的正则表达式作为一个值 [约瑟夫·乔斯塔之子]=>s/o。约瑟夫乔斯塔 问题是,由于没有验证,用户输入了不同的变体,如 s/o,s/,s/Joseph,等 到目前为止我已经做到了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\/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} ";
});
你的问题是什么?