public void OneMatch() { Regex2 regex = new Regex2("thing", AlgorithmType); Match2 match = regex.Match("Something or other"); Assert.AreEqual(Factory.CreateMatch(4, 5, "thing"), match); }
public void NoMatch() { Regex2 regex = new Regex2("xyz", AlgorithmType); Match2 match = regex.Match("Something or other"); Assert.AreEqual(Match2.Empty, match); }
private static void testRegexMatches(string input, string pattern, RegexOptions options, int times) { Console.WriteLine("Pattern: {0}", pattern.ShowVerbatim()); if (options != RegexOptions.None) { Console.WriteLine("Options: [{0}]", options.ToString()); } MemoryProfiler memoryProfiler; if (useMemoryProfiler) { memoryProfiler = MemoryProfiler.StartNew(); } Stopwatch stopwatch = Stopwatch.StartNew(); MatchCollection2 matches = null; //Msoft.MatchCollection matches = null; for (int i = 0; i < times; i++) { matches = new Regex2(pattern, AlgorithmType.Backtracking, options).Matches(input); } //matches = new Msoft.Regex(pattern, RegexAssert.ToMsoftRegexOptions(options)).Matches(input); if (useMemoryProfiler) { memoryProfiler.Reset(); } Console.WriteLine("Matches: {0:#,##0}", matches.Count); //string v; //foreach (var m in matches.Cast<Match2>()) ////foreach (var m in matches.Cast<Msoft.Match>()) // v = m.Value; decimal elapsed = ((decimal)stopwatch.ElapsedMilliseconds) / 1000; if (useMemoryProfiler) { long deltaBefore = memoryProfiler.DeltaValue; memoryProfiler.CollectGC(); long deltaAfter = memoryProfiler.DeltaValue; if (matches.Count > 0) { Console.WriteLine("Last: {0:#,##0} chars", matches[matches.Count - 1].Value.Length); } Console.WriteLine("Memory: {0,10:#,##0} bytes", deltaBefore); Console.WriteLine("AfterGC: {0,10:#,##0} bytes", deltaAfter); } Console.WriteLine("Time: {0:#0.000} sec.\n", elapsed); }
private static void displayMatches(string input, string pattern, AlgorithmType algorithmType, RegexOptions options) { //RegexAssert.DisplayPattern(pattern); var matches = new Regex2(pattern, algorithmType, options).Matches(input); RegexAssert.DisplayMatches(input, pattern, algorithmType, options, matches); }
public void FindAllMatches(byte[] input) { var e = Regex2.Matches(new String8(input, 0, input.Length), Regex).GetEnumerator(); while (e.MoveNext()) { } }
public void FindAllMatches(string input) { byte[] buffer = null; String8 input8 = String8.Convert(input, ref buffer); var e = Regex2.Matches(input8, Regex).GetEnumerator(); while (e.MoveNext()) { } }
private static void createRegex(string pattern, int times) { Console.WriteLine("Pattern: {0}", pattern.ShowVerbatim()); Stopwatch stopwatch = Stopwatch.StartNew(); Regex2 regex; for (int i = 0; i < times; i++) regex = new Regex2(pattern, AlgorithmType.Backtracking); decimal elapsed = ((decimal)stopwatch.ElapsedMilliseconds) / 1000; Console.WriteLine("Time: {0:#0.000} sec.\n", elapsed); }
public void TwoMatches() { Regex2 regex = new Regex2("thing", AlgorithmType); Match2[] matches = regex.Matches("A thing or another thing").ToArray(); Match2[] expected = new Match2[] { Factory.CreateMatch(2, 5, "thing"), Factory.CreateMatch(19, 5, "thing") }; CollectionAssert.AreEqual(expected, matches, "MatchCollection"); Assert.AreEqual(matches[1], matches[0].NextMatch(), "NextMatch/1."); Assert.AreEqual(Match2.Empty, matches[1].NextMatch(), "NextMatch/2."); Assert.AreEqual(Match2.Empty, matches[1].NextMatch().NextMatch(), "NextMatch/3."); }
private static void createRegex(string pattern, int times) { Console.WriteLine("Pattern: {0}", pattern.ShowVerbatim()); Stopwatch stopwatch = Stopwatch.StartNew(); Regex2 regex; for (int i = 0; i < times; i++) { regex = new Regex2(pattern, AlgorithmType.Backtracking); } decimal elapsed = ((decimal)stopwatch.ElapsedMilliseconds) / 1000; Console.WriteLine("Time: {0:#0.000} sec.\n", elapsed); }
public static List <string> Garbage2(this string input) { var result = new List <string>(); var matchCollection = Regex2.Matches(input); if (matchCollection.Count != 0) { //foreach (Match c in matchCollection) //{ // var s = c.Value.Substring(1, c.Value.Length - 2);//; // if (s.IsSurrounded()) // { // sum += Score(s, level + 1); // } // else // { // int start = 0; // for (int j = 0; start + j < s.Length; j++) // { // if (s.Substring(start, j + 1).IsSurrounded()) // { // sum += Score(s.Substring(start, j + 1), level + 1); // start += j + 2; // j = 0; // Console.WriteLine(); // } // else // { // Console.WriteLine(); // } // } // //foreach (var s1 in s.Split(',')) // //{ // // sum += Score(s1, level + 1); // //} // } // // //} } return(result); }
public static void AreMatchesSameAsMsoft(string input, string pattern, AlgorithmType algorithmType, RegexOptions options) { //DisplayPattern(pattern); Match2[] actual = new Regex2(pattern, algorithmType, options).Matches(input).ToArray(); DisplayMatches(input, pattern, algorithmType, options, actual); Match2[] expected = CreateMatches(Msoft.Regex.Matches(input, pattern, ToMsoftRegexOptions(options))); try { CollectionAssert.AreEqual(expected, actual); } catch (Exception ex) { throw new AssertionException(formatException(input, pattern, options, ex)); } }
public void MatchOverlap() { Match2[] matches = new Regex2("thing", AlgorithmType).Matches("Some thinthing or another").ToArray(); Match2[] expected = new Match2[] { Factory.CreateMatch(9, 5, "thing") }; CollectionAssert.AreEqual(expected, matches, "False overlap."); matches = new Regex2("alfa", AlgorithmType).Matches("This is alfalfa").ToArray(); expected = new Match2[] { Factory.CreateMatch(8, 4, "alfa") }; CollectionAssert.AreEqual(expected, matches, "Real overlap."); matches = new Regex2("alfa", AlgorithmType).Matches("This is alfalfalfa").ToArray(); expected = new Match2[] { Factory.CreateMatch(8, 4, "alfa"), Factory.CreateMatch(14, 4, "alfa") }; CollectionAssert.AreEqual(expected, matches, "Double overlap."); }
private static void Main(string[] args) { Regex2.Test(); Console.WriteLine("Regex2.Test() --> success"); Console.ReadKey(); }
private static void testRegexMatches(string input, string pattern, RegexOptions options, int times) { Console.WriteLine("Pattern: {0}", pattern.ShowVerbatim()); if (options != RegexOptions.None) Console.WriteLine("Options: [{0}]", options.ToString()); MemoryProfiler memoryProfiler; if (useMemoryProfiler) memoryProfiler = MemoryProfiler.StartNew(); Stopwatch stopwatch = Stopwatch.StartNew(); MatchCollection2 matches = null; //Msoft.MatchCollection matches = null; for (int i = 0; i < times; i++) matches = new Regex2(pattern, AlgorithmType.Backtracking, options).Matches(input); //matches = new Msoft.Regex(pattern, RegexAssert.ToMsoftRegexOptions(options)).Matches(input); if (useMemoryProfiler) memoryProfiler.Reset(); Console.WriteLine("Matches: {0:#,##0}", matches.Count); //string v; //foreach (var m in matches.Cast<Match2>()) ////foreach (var m in matches.Cast<Msoft.Match>()) // v = m.Value; decimal elapsed = ((decimal)stopwatch.ElapsedMilliseconds) / 1000; if (useMemoryProfiler) { long deltaBefore = memoryProfiler.DeltaValue; memoryProfiler.CollectGC(); long deltaAfter = memoryProfiler.DeltaValue; if (matches.Count > 0) Console.WriteLine("Last: {0:#,##0} chars", matches[matches.Count - 1].Value.Length); Console.WriteLine("Memory: {0,10:#,##0} bytes", deltaBefore); Console.WriteLine("AfterGC: {0,10:#,##0} bytes", deltaAfter); } Console.WriteLine("Time: {0:#0.000} sec.\n", elapsed); }
public IEngine Compile(string pattern) { Regex2.IsMatch(String8.Empty, pattern); return(new Re2ManagedEngine(pattern)); }