背景
すっかり忘れてて、C# で使おうとしたら、意外に参照方法に手間取ったための備忘録
概要
基本はこの記事へどうぞ。
実際の使用例
LinqPad での利用例
Match
Match
displayName.Dump("<<< displayName >>>");
var pattern = @"(?<FamilyName>\w+)\.(?<GivenName>\w+)@(?<DomainName>.+)";
var Match = Regex.Match(displayName, pattern);
if (Match.Success){
Match.Groups["FamilyName"].Value.Dump("FamilyName");
Match.Groups["GivenName"].Value.Dump("GivenName");
Match.Groups["DomainName"].Value.Dump("DomainName");
}
Matches
Matches
var source = "<code>// hage hage </code>\n<code>public string hagehage {get; set;}</code>";
var pattern = @"<(?<CodeTag>code)>(?<Source>.*)</\k<CodeTag>>";
var Matches = Regex.Matches(source, pattern);
foreach (Match match in Matches){
match.Value.Dump("<<< Value >>>");
if (match.Success){
match.Groups["CodeTag"].Value.Dump("CodeTag");
match.Groups["Source"].Value.Dump("Source");
}
else
{
"Not Found!".Dump();
}
}
keyword
how to use named group of regular expression