最初の文字から検索を開始し、指定した正規表現によって定義されている文字パターンに一致するすべての対象を置換文字列に置き換えます。オプションを指定して、一致する動作を変更できます。また、一致する対象が見つかるたびに、置換を評価する MatchEvaluator デリゲートが呼び出されます。
Overloads Public Shared Function Replace( _
ByVal input As String, _ ByVal pattern As String, _ ByVal evaluator As MatchEvaluator, _ ByVal options As RegexOptions _) As String
[C#]
public static string Replace(stringinput,stringpattern,MatchEvaluatorevaluator,RegexOptionsoptions);
[C++]
public: static String* Replace(String* input,String* pattern,MatchEvaluator* evaluator,RegexOptionsoptions);
[JScript]
public static function Replace(
input : String,pattern : String,evaluator : MatchEvaluator,options : RegexOptions) : String;
パラメータ
- input
変更対象の文字列。 - pattern
一致させる正規表現パターン。 - evaluator
置換を 1 つずつ評価する MatchEvaluator 。 - options
ビットごとの OR 演算による RegexOption 列挙値の組み合わせ。
戻り値
変更後の文字列。
解説
MatchEvaluator 型は、入力として単一の Match を取得し、文字列を返すデリゲートです。次のように宣言します。
public delegate String RegexMatchEvaluator(Match match);このデリゲートは、一致する対象が置換中に見つかるたびに呼び出されます。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
Regex クラス | Regex メンバ | System.Text.RegularExpressions 名前空間 | Regex.Replace オーバーロードの一覧