パターンを変更するオプションを使用して、指定した正規表現の Regex クラスの新しいインスタンスを初期化およびコンパイルします。
名前空間: System.Text.RegularExpressions
アセンブリ: System (system.dll 内)
構文
'宣言
Public Sub New ( _
pattern As String, _
options As RegexOptions _
)
'使用
Dim pattern As String
Dim options As RegexOptions
Dim instance As New Regex(pattern, options)
public Regex (
string pattern,
RegexOptions options
)
public:
Regex (
String^ pattern,
RegexOptions options
)
public Regex (
String pattern,
RegexOptions options
)
public function Regex (
pattern : String,
options : RegexOptions
)
適用できません。
パラメータ
- pattern
一致させる正規表現パターン。
- options
ビットごとの OR 演算による RegexOptions 列挙値の組み合わせ。
例外
例外の種類 | 条件 |
---|---|
正規表現の解析エラー。 |
|
pattern が null 参照 (Visual Basic では Nothing) です。 |
|
options に無効なフラグが含まれています。 |
解説
pattern パラメータは、一致する文字列をシンボルで表すさまざまな正規表現言語要素で構成されています。正規表現の詳細については、「.NET Framework の正規表現」および「正規表現言語要素」を参照してください。
Regex オブジェクトは変更不可であるため、そのオブジェクトの作成時に定義された一致パラメータに対してしか使用できません。しかし、再コンパイルせずに何度でも使用できます。
使用例
このコンストラクタを使用し、パターンおよびオプションを指定して正規表現をインスタンス化するコード例を次に示します。
// Define a regular expression for repeated words.
Regex rx = new Regex(@"\b(?<word>\w+)\s+(\k<word>)\b",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
// Define a regular expression for repeated words.
Regex^ rx = gcnew Regex( "\\b(?<word>\\w+)\\s+(\\k<word>)\\b",static_cast<RegexOptions>(RegexOptions::Compiled | RegexOptions::IgnoreCase) );
// Define a regular expression for repeated words.
Regex rx = new Regex("\\b(?<word>\\w+)\\s+(\\k<word>)\\b",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
プラットフォーム
Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition
Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。
バージョン情報
.NET Framework
サポート対象 : 3.0,2.0,1.1,1.0
.NET Compact Framework
サポート対象 : 2.0,1.0
XNA Framework
サポート対象 : 1.0
参照
関連項目
Regex クラス
Regex メンバ
System.Text.RegularExpressions 名前空間