///
/// Uses regular expressions to replace parts of a string.
///
/// The input string.
/// The regular expression pattern.
/// The replacement value.
/// The newly created string
///
///
/// var s = "12345";
/// var replaced = s.ReplaceWith(@"\d", m => string.Concat(" -", m.Value, "- "));
///
///
public static string ReplaceWith(this string value, string regexPattern, string replaceValue)
{
return ReplaceWith(value, regexPattern, regexPattern, RegexOptions.None);
}
///
/// Uses regular expressions to replace parts of a string.
///
/// The input string.
/// The regular expression pattern.
/// The replacement value.
/// The regular expression options.
/// The newly created string
///
///
/// var s = "12345";
/// var replaced = s.ReplaceWith(@"\d", m => string.Concat(" -", m.Value, "- "));
///
///
public static string ReplaceWith(this string value, string regexPattern, string replaceValue, RegexOptions options)
{
return Regex.Replace(value, regexPattern, replaceValue, options);
}
///
/// Uses regular expressions to replace parts of a string.
///
/// The input string.
/// The regular expression pattern.
/// The replacement method / lambda expression.
/// The newly created string
///
///
/// var s = "12345";
/// var replaced = s.ReplaceWith(@"\d", m => string.Concat(" -", m.Value, "- "));
///
///
public static string ReplaceWith(this string value, string regexPattern, MatchEvaluator evaluator)
{
return ReplaceWith(value, regexPattern, RegexOptions.None, evaluator);
}
///
/// Uses regular expressions to replace parts of a string.
///
/// The input string.
/// The regular expression pattern.
/// The regular expression options.
/// The replacement method / lambda expression.
/// The newly created string
///
///
/// var s = "12345";
/// var replaced = s.ReplaceWith(@"\d", m => string.Concat(" -", m.Value, "- "));
///
///
public static string ReplaceWith(this string value, string regexPattern, RegexOptions options, MatchEvaluator evaluator)
{
return Regex.Replace(value, regexPattern, evaluator, options);
}
|