RegexOptions 열거형

정의

정규식 옵션을 설정하는 데 사용하는 열거형 값을 제공합니다.

이 열거형은 멤버 값의 비트 조합을 지원합니다.

public enum class RegexOptions
[System.Flags]
public enum RegexOptions
[<System.Flags>]
type RegexOptions = 
Public Enum RegexOptions
상속
RegexOptions
특성

필드

Compiled 8

정규식이 해석되는 대신 MSIL 코드로 컴파일되도록 지정합니다. 컴파일된 정규식은 초기화 시간을 희생하여 런타임 성능을 최대화합니다. Options 메서드를 호출할 때는 CompileToAssembly(RegexCompilationInfo[], AssemblyName) 속성에 이 값을 할당하지 말아야 합니다. 자세한 내용은 정규식 옵션 문서의 “컴파일된 정규식” 섹션을 참조하세요.

CultureInvariant 512

언어의 문화권 차이점이 무시되도록 지정합니다. 자세한 내용은 정규식 옵션 문서의 “고정 문화권을 사용한 비교” 섹션을 참조하세요.

ECMAScript 256

해당 식에 ECMAScript 규격 동작을 사용 가능하게 합니다. 이 값은 IgnoreCase, MultilineCompiled 값과 함께만 사용할 수 있습니다. 이 값을 다른 값과 함께 사용하면 예외가 발생합니다.

ECMAScript 옵션에 대한 자세한 내용은 정규식 옵션 문서의 “ECMAScript 일치 동작” 섹션을 참조하세요.

ExplicitCapture 4

해당 형식(?<name>...)의 명시적으로 명명되거나 번호가 매겨진 그룹만 유효한 캡처가 되도록 지정합니다. 이렇게 하면 명명되지 않은 괄호가 해당 식(?:...)과 같이 구문적으로 어색한 부분 없이 비캡처링 그룹의 역할을 할 수 있습니다. 자세한 내용은 정규식 옵션 문서의 “명시적 캡처만 해당” 섹션을 참조하세요.

IgnoreCase 1

대/소문자를 구분하지 않고 일치 항목을 찾도록 지정합니다. 자세한 내용은 정규식 옵션 문서의 “대/소문자를 구분하지 않는 일치” 섹션을 참조하세요.

IgnorePatternWhitespace 32

이스케이프되지 않은 공백을 패턴에서 제거하고 주석을 #으로 표시할 수 있게 합니다. 그러나 이 값은 문자 클래스, 숫자 수량자 또는 개별 정규식 언어 요소의 시작을 표시하는 토큰에서 영향을 주거나 공백을 제거하지 않습니다. 자세한 내용은 정규식 옵션 아티클의 “공백 무시” 섹션을 참조하세요.

Multiline 2

여러 줄 모드입니다. 전체 문자열의 시작과 끝뿐만 아니라 모든 줄의 시작과 끝에서 각각 일치하도록 ^과 $의 의미를 변경합니다. 자세한 내용은 정규식 옵션 문서의 “여러 줄 모드” 섹션을 참조하세요.

NonBacktracking 1024

역추적을 방지하고 입력 길이에서 선형 시간 처리를 보장하는 방법을 사용하여 일치를 사용하도록 설정합니다.

None 0

옵션이 설정되지 않도록 지정합니다. 정규식 엔진의 기본 동작에 대한 자세한 내용은 정규식 옵션 문서의 “기본 옵션” 섹션을 참조하세요.

RightToLeft 64

왼쪽에서 오른쪽이 아닌 오른쪽에서 왼쪽으로 검색이 진행되도록 지정합니다. 자세한 내용은 정규식 옵션 문서의 “오른쪽에서 왼쪽 모드” 섹션을 참조하세요.

Singleline 16

한 줄 모드를 지정합니다. \n을 제외한 모든 문자가 아닌 \n을 포함한 모든 문자와 일치하도록 점(.)의 의미를 변경합니다. 자세한 내용은 정규식 옵션 문서의 “한 줄 모드” 섹션을 참조하세요.

예제

다음 예제에서는 텍스트에서 반복되는 단어를 식별하지만 다른 RegexOptions 값을 사용하여 인스턴스화되는 두 정규식을 정의합니다. 첫 번째 정규식은 대/소문자를 구분하지 않습니다. 대/소문자가 이전 단어와 동일한지 여부를 결정할 때는 대/소문자가 무시됩니다. 두 번째 정규식은 대/소문자를 구분합니다. 단어는 중복으로 간주되려면 이전 단어의 대/소문자를 정확히 일치시켜야 합니다.

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

설명

클래스의 RegexOptions 다음 멤버 Regex 에 대한 매개 변수로 값을 제공할 수 있습니다.

RegexOptions 값을 생성자에 매개 변수로 제공하거나 속성에 RegexCompilationInfo 직접 RegexCompilationInfo.Options 할당할 수도 있습니다. 그런 다음, 메서드 호출에 결과 RegexCompilationInfo 개체가 Regex.CompileToAssembly 사용됩니다.

열거형의 RegexOptions 멤버(특히, 해당 ExplicitCapture, IgnoreCase``MultilineSingleline 멤버별)에서 제공하는 몇 가지 옵션은 정규식 패턴의 인라인 옵션 문자를 사용하여 대신 제공할 수 있습니다. 자세한 내용은 정규식 옵션을 참조하세요.

적용 대상

추가 정보