RegexOptions Sabit listesi

Tanım

Normal ifade seçeneklerini ayarlamak için kullanılacak numaralandırılmış değerler sağlar.

Bu sabit listesi, üyeleri için bit düzeyinde karşılaştırmayı destekler.

public enum class RegexOptions
[System.Flags]
public enum RegexOptions
[<System.Flags>]
type RegexOptions = 
Public Enum RegexOptions
Devralma
RegexOptions
Öznitelikler

Alanlar

Compiled 8

Normal ifadenin yorumlanmak yerine MSIL koduna derlendiğini belirtir. Derlenmiş normal ifadeler, başlatma süresi pahasına çalışma zamanı performansını en üst düzeye çıkarır. Yöntemi çağrılırken CompileToAssembly(RegexCompilationInfo[], AssemblyName) bu değer özelliğine Options atanmamalıdır. Daha fazla bilgi için Normal İfade Seçenekleri makalesindeki "Derlenmiş Normal İfadeler " bölümüne bakın.

CultureInvariant 512

Dildeki kültürel farklılıkların yoksayıldığını belirtir. Daha fazla bilgi için Normal İfade Seçenekleri makalesindeki "Sabit Kültürü Kullanarak Karşılaştırma" bölümüne bakın.

ECMAScript 256

İfade için ECMAScript uyumlu davranışı etkinleştirir. Bu değer yalnızca , Multilineve Compiled değerleriyle IgnoreCasebirlikte kullanılabilir. Bu değerin diğer değerlerle kullanılması bir özel durumla sonuç verir.

Seçeneği hakkında ECMAScript daha fazla bilgi için Normal İfade Seçenekleri makalesindeki "ECMAScript Eşleştirme Davranışı" bölümüne bakın.

ExplicitCapture 4

Yalnızca geçerli yakalamaların formun açıkça adlandırıldığını veya numaralandırıldığını belirtir (?< ad>...). Bu, adsız ayraçların ifadenin söz dizimsel clumsiness olmadan kapsülleyici olmayan gruplar olarak davranmasına olanak tanır (?:...). Daha fazla bilgi için Normal İfade Seçenekleri makalesindeki "Yalnızca Açık Yakalamalar" bölümüne bakın.

IgnoreCase 1

Büyük/küçük harfe duyarsız eşleştirmeyi belirtir. Daha fazla bilgi için Normal İfade Seçenekleri makalesindeki "Büyük/Küçük Harfe Duyarsız Eşleştirme" bölümüne bakın.

IgnorePatternWhitespace 32

Desenden boşaltılmamış boş alanı ortadan kaldırır ve # ile işaretlenmiş açıklamaları etkinleştirir. Ancak bu değer, tek tek normal ifade dili öğelerinin başlangıcını işaretleyen karakter sınıflarındaki, sayısal niceleyicilerdeki veya belirteçlerdeki boşlukları etkilemez veya ortadan kaldırmaz. Daha fazla bilgi için Normal İfade Seçenekleri makalesinin "Boşluğu Yoksay" bölümüne bakın.

Multiline 2

Çok satırlı mod. ^ ve $ değerinin anlamını değiştirerek dizenin yalnızca başında ve sonunda değil, sırasıyla herhangi bir satırın başında ve sonunda eşleşmesini sağlar. Daha fazla bilgi için Normal İfade Seçenekleri makalesindeki "Çok Satırlı Mod" bölümüne bakın.

NonBacktracking 1024

Geri izlemeyi önleyen ve girişin uzunluğunda doğrusal zaman işlemeyi garanti eden bir yaklaşım kullanarak eşleştirmeyi etkinleştirin.

None 0

Hiçbir seçeneğin ayarlı olmadığını belirtir. Normal ifade altyapısının varsayılan davranışı hakkında daha fazla bilgi için Normal İfade Seçenekleri makalesindeki "Varsayılan Seçenekler" bölümüne bakın.

RightToLeft 64

Aramanın soldan sağa değil sağdan sola doğru olacağını belirtir. Daha fazla bilgi için Normal İfade Seçenekleri makalesindeki "Sağdan Sola Mod" bölümüne bakın.

Singleline 16

Tek satır modunu belirtir. Noktanın (.) anlamını değiştirerek her karakterle eşleşir (\n hariç her karakter yerine). Daha fazla bilgi için Normal İfade Seçenekleri makalesindeki "Tek Satırlı Mod" bölümüne bakın.

Örnekler

Aşağıdaki örnek, metindeki yinelenen sözcükleri tanımlayan ancak farklı RegexOptions değerler kullanılarak örneklenmiş iki normal ifade tanımlar. İlk normal ifade büyük/küçük harfe duyarlı değildir; bir sözcüğün önceki sözcükle aynı olup olmadığı belirlenirken büyük/küçük harf yoksayılır. İkinci normal ifade büyük/küçük harfe duyarlıdır; bir sözcüğün, yinelenen olarak kabul edilmesi için önceki sözcüğün büyük/küçük harfiyle tam olarak eşleşmesi gerekir.

using System;
using System.Text.RegularExpressions;

public class Test
{
    public static void Main ()
    {
        // Define a case-insensitive regular expression for repeated words.
        Regex rxInsensitive = new Regex(@"\b(?<word>\w+)\s+(\k<word>)\b",
          RegexOptions.Compiled | RegexOptions.IgnoreCase);
        // Define a case-sensitive regular expression for repeated words.
        Regex rxSensitive = new Regex(@"\b(?<word>\w+)\s+(\k<word>)\b",
          RegexOptions.Compiled);

        // Define a test string.        
        string text = "The the quick brown fox  fox jumps over the lazy dog dog.";
        
        // Find matches using case-insensitive regular expression.
        MatchCollection matches = rxInsensitive.Matches(text);

        // Report the number of matches found.
        Console.WriteLine("{0} matches found in:\n   {1}", 
                          matches.Count, 
                          text);

        // Report on each match.
        foreach (Match match in matches)
        {
            GroupCollection groups = match.Groups;
            Console.WriteLine("'{0}' repeated at positions {1} and {2}",  
                              groups["word"].Value, 
                              groups[0].Index, 
                              groups[1].Index);
        }
        Console.WriteLine();
        
        // Find matches using case-sensitive regular expression.
        matches = rxSensitive.Matches(text);

        // Report the number of matches found.
        Console.WriteLine("{0} matches found in:\n   {1}", 
                          matches.Count, 
                          text);

        // Report on each match.
        foreach (Match match in matches)
        {
            GroupCollection groups = match.Groups;
            Console.WriteLine("'{0}' repeated at positions {1} and {2}",  
                              groups["word"].Value, 
                              groups[0].Index, 
                              groups[1].Index);
        }
    }
}
// The example produces the following output to the console:
//       3 matches found in:
//          The the quick brown fox  fox jumps over the lazy dog dog.
//       'The' repeated at positions 0 and 4
//       'fox' repeated at positions 20 and 25
//       'dog' repeated at positions 50 and 54
//       
//       2 matches found in:
//          The the quick brown fox  fox jumps over the lazy dog dog.
//       'fox' repeated at positions 20 and 25
//       'dog' repeated at positions 50 and 54
Imports System.Text.RegularExpressions

Public Module Test

    Public Sub Main()
        ' Define a case-insensitive regular expression for repeated words.
        Dim rxInsensitive As New Regex("\b(?<word>\w+)\s+(\k<word>)\b", _
               RegexOptions.Compiled Or RegexOptions.IgnoreCase)
        ' Define a case-sensitive regular expression for repeated words.
        Dim rxSensitive As New Regex("\b(?<word>\w+)\s+(\k<word>)\b", _
               RegexOptions.Compiled)

        ' Define a test string.        
        Dim text As String = "The the quick brown fox  fox jumps over the lazy dog dog."
        
        ' Find matches using case-insensitive regular expression.
        Dim matches As MatchCollection = rxInsensitive.Matches(text)

        ' Report the number of matches found.
        Console.WriteLine("{0} matches found in:", matches.Count)
        Console.WriteLine("   {0}", text)

        ' Report on each match.
        For Each match As Match In matches
            Dim groups As GroupCollection = match.Groups
            Console.WriteLine("'{0}' repeated at positions {1} and {2}", _ 
                              groups.Item("word").Value, _
                              groups.Item(0).Index, _
                              groups.Item(1).Index)
        Next
        Console.WriteLine()
        
        ' Find matches using case-sensitive regular expression.
        matches = rxSensitive.Matches(text)

        ' Report the number of matches found.
        Console.WriteLine("{0} matches found in:", matches.Count)
        Console.WriteLine("   {0}", text)

        ' Report on each match.
        For Each match As Match In matches
            Dim groups As GroupCollection = match.Groups
            Console.WriteLine("'{0}' repeated at positions {1} and {2}", _ 
                              groups.Item("word").Value, _
                              groups.Item(0).Index, _
                              groups.Item(1).Index)
        Next
        Console.WriteLine()
    End Sub
End Module
' The example produces the following output to the console:
'       3 matches found in:
'          The the quick brown fox  fox jumps over the lazy dog dog.
'       'The' repeated at positions 0 and 4
'       'fox' repeated at positions 20 and 25
'       'dog' repeated at positions 50 and 54
'       
'       2 matches found in:
'          The the quick brown fox  fox jumps over the lazy dog dog.
'       'fox' repeated at positions 20 and 25
'       'dog' repeated at positions 50 and 54

Açıklamalar

Sınıfın RegexOptions aşağıdaki üyelerine Regex parametre olarak bir değer sağlanabilir:

Bir RegexOptions değer oluşturucuya RegexCompilationInfo parametre olarak da sağlanabilir veya doğrudan özelliğine RegexCompilationInfo.Options atanabilir. Sonuçta elde edilen RegexCompilationInfo nesne daha sonra yöntemine yapılan çağrıda Regex.CompileToAssembly kullanılır.

Sabit listesi üyeleri RegexOptions tarafından sağlanan çeşitli seçenekler (özellikle , IgnoreCase, Multilineve Singleline üyeleri tarafındanExplicitCapture), bunun yerine normal ifade deseninde satır içi seçenek karakteri kullanılarak sağlanabilir. Ayrıntılar için bkz. Normal İfade Seçenekleri.

Şunlara uygulanır

Ayrıca bkz.