複数行も可能
var bb="{{{aiueo}}}".capture(@"{{{", @"}}}"); //aiueo
public static class RegexStringExtension{
public static string capture(this string @this, string head, string tail)
{
/*usage
var aa="(aiueo)".capture(@"\(",@"\)"); //aiueo
var bb="{{{aiueo}}}".capture(@"{{{", @"}}}"); //aiueo
*/
var p = head + "(.*?)" + tail;
var ma = Regex.Match(@this, p, RegexOptions.Singleline);
if (!ma.Success) return "";
return ma.Groups[1].Value;
}
}
↧