Beispiel #1
0
        public FlexMatch Match(FlexString input, string pattern, RegexOptions options = RegexOptions.None, TimeSpan timeout = default, string captureGroup = null)
        {
            // Note: Instance Regex.Match has no timeout overload.
            Regex regex = GetOrCreateRegex(pattern, options);

            return(DotNetRegex.ToFlex(regex.Match(input), captureGroup));
        }
Beispiel #2
0
        public IEnumerable <FlexMatch> Matches(FlexString input, string pattern, RegexOptions options = RegexOptions.None, TimeSpan timeout = default, string captureGroup = null)
        {
            if (timeout == default)
            {
                timeout = DefaultTimeout;
            }
            var w = Stopwatch.StartNew();

            Regex regex = GetOrCreateRegex(pattern, options);

            foreach (Match m in regex.Matches(input))
            {
                yield return(DotNetRegex.ToFlex(m, captureGroup));

                // Instance Regex.Matches has no overload; check timeout between matches
                // (MatchesCollection *is* lazily computed).
                if (w.Elapsed > timeout)
                {
                    break;
                }
            }
        }