Regex replace constructor missing option?

Viewed 25

is it possible for someone to explain why do we see two different kinds of constructors for (how it looks, the same?) method replace ?

    PS Y:\> [regex]::Replace

OverloadDefinitions
-------------------
static string Replace(string input, string pattern, string replacement)
static string Replace(string input, string pattern, string replacement, System.Text.RegularExpressions.RegexOptions options)
static string Replace(string input, string pattern, string replacement, System.Text.RegularExpressions.RegexOptions options, timespan matchTimeout)
static string Replace(string input, string pattern, System.Text.RegularExpressions.MatchEvaluator evaluator)
static string Replace(string input, string pattern, System.Text.RegularExpressions.MatchEvaluator evaluator, System.Text.RegularExpressions.RegexOptions options)
static string Replace(string input, string pattern, System.Text.RegularExpressions.MatchEvaluator evaluator, System.Text.RegularExpressions.RegexOptions options, timespan matchTimeout)
T

The one below has the 'count' option where i can specify how many times it should be replaced if found more times.

 PS Y:\> ([regex]"\.").Replace

OverloadDefinitions
-------------------
string Replace(string input, string replacement)
string Replace(string input, string replacement, int count)
string Replace(string input, string replacement, int count, int startat)
string Replace(string input, System.Text.RegularExpressions.MatchEvaluator evaluator)
string Replace(string input, System.Text.RegularExpressions.MatchEvaluator evaluator, int count)
string Replace(string input, System.Text.RegularExpressions.MatchEvaluator evaluator, int count, int startat)

I don't understand why those are different constructors, it's the same regex.replace ? Or isn't ? :)

In the example with count option i am allowed to do:

 ([regex]"\.").Replace("IT . will . replace. first. dot. only"," | ",1)
IT  |  will . replace. first. dot. only

so this is bit easier for me than doing

[regex]::Replace("IT . will . replace. first. dot. only","(.*?)\.(.*)", '$1 | $2')
IT  |  will . replace. first. dot. only
0 Answers
Related