Regex.MatchTimeout 속성

정의

현재 인스턴스의 시간 제한 간격을 가져옵니다.

public:
 property TimeSpan MatchTimeout { TimeSpan get(); };
public TimeSpan MatchTimeout { get; }
member this.MatchTimeout : TimeSpan
Public ReadOnly Property MatchTimeout As TimeSpan

속성 값

RegexMatchTimeoutException이 throw되기 전에 패턴 일치 작업에서 경과할 수 있는 최대 시간 간격이며, 제한 시간이 비활성화된 경우는 InfiniteMatchTimeout입니다.

설명

속성은 MatchTimeout 작업 시간이 초과되기 전에 일치하는 단일 작업을 실행하는 instance 대략적인 최대 시간 간격 Regex 을 정의합니다. 정규식 엔진은 시간 제한 간격이 RegexMatchTimeoutException 경과한 후 다음 타이밍 검사 동안 예외를 throw합니다. 이렇게 하면 정규식 엔진이 과도한 역추적이 필요한 입력 문자열을 처리할 수 없습니다. 자세한 내용은 정규식에 대한 역추적모범 사례를 참조하세요.

이 속성은 읽기 전용입니다. 개인에 대 한 해당 값을 명시적으로 설정할 수 있습니다 Regex 호출 하 여 개체를 Regex.Regex(String, RegexOptions, TimeSpan) 생성자; 하 고 모든 해당 값을 설정할 수 있습니다 Regex 호출 하 여 일치 하는 애플리케이션 도메인에서 작업은 AppDomain.SetData 메서드 제공 하는 TimeSpan 다음 예제와 같이 "REGEX_DEFAULT_MATCH_TIMEOUT" 속성에 대 한 값입니다.

using System;
using System.Text.RegularExpressions;

public class Example
{
   public static void Main()
   {
      AppDomain domain = AppDomain.CurrentDomain;
      // Set a timeout interval of 2 seconds.
      domain.SetData("REGEX_DEFAULT_MATCH_TIMEOUT", TimeSpan.FromSeconds(2));
      Object timeout = domain.GetData("REGEX_DEFAULT_MATCH_TIMEOUT");
      Console.WriteLine("Default regex match timeout: {0}",
                         timeout == null ? "<null>" : timeout);

      Regex rgx = new Regex("[aeiouy]");
      Console.WriteLine("Regular expression pattern: {0}", rgx.ToString());
      Console.WriteLine("Timeout interval for this regex: {0} seconds",
                        rgx.MatchTimeout.TotalSeconds);
   }
}
// The example displays the following output:
//       Default regex match timeout: 00:00:02
//       Regular expression pattern: [aeiouy]
//       Timeout interval for this regex: 2 seconds
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim domain As AppDomain = AppDomain.CurrentDomain
      ' Set a timeout interval of 2 seconds.
      domain.SetData("REGEX_DEFAULT_MATCH_TIMEOUT", TimeSpan.FromSeconds(2))
      Dim timeout As Object = domain.GetData("REGEX_DEFAULT_MATCH_TIMEOUT")
      Console.WriteLine("Default regex match timeout: {0}",
                         If(timeout Is Nothing, "<null>", timeout))

      Dim rgx As New Regex("[aeiouy]")
      Console.WriteLine("Regular expression pattern: {0}", rgx.ToString())
      Console.WriteLine("Timeout interval for this regex: {0} seconds",
                        rgx.MatchTimeout.TotalSeconds)
   End Sub
End Module
' The example displays the following output:
'       Default regex match timeout: 00:00:02
'       Regular expression pattern: [aeiouy]
'       Timeout interval for this regex: 2 seconds

제한 시간 간격을 명시적으로 설정하지 않으면 기본값 Regex.InfiniteMatchTimeout 이 사용되며 일치 작업은 시간 초과되지 않습니다.

적용 대상