Example #1
0
        private static void FunctionalRegexSamples()
        {
            #region Regex: AC
            source
            .Detect(p => p.SingleElement(e => e.Field1 == "A")
                    .SingleElement(e => e.Field1 == "C"))
            .SubscribeToConsole();

            source
            .DefinePattern()
            .SingleElement(e => e.Field1 == "A")
            .SingleElement(e => e.Field1 == "C")
            .Detect()
            .SubscribeToConsole();
            #endregion

            #region Regex: A(B*)C and accumulate a sum of Field2 for B*
            source
            .Detect(0, p => p.SingleElement(e => e.Field1 == "A", (ev, d) => 0)
                    .KleeneStar(r => r.SingleElement(e => e.Field1 == "B", (ev, d) => d + ev.Field2))
                    .SingleElement(e => e.Field1 == "C"))
            .SubscribeToConsole();

            source
            .DefinePattern()
            .SetRegister(0)     // or .SetRegister<int>()
            .SingleElement(e => e.Field1 == "A")
            .KleeneStar(r => r.SingleElement(e => e.Field1 == "B", (ev, d) => d + ev.Field2))
            .SingleElement(e => e.Field1 == "C")
            .Detect()
            .SubscribeToConsole();
            #endregion
        }
Example #2
0
        static void FunctionalRegexExamples()
        {
            // Use functional notation to express patterns in a compact form (without having to utter types)
            #region Regex: AC
            Console.WriteLine("Regex 1: AC");
            Console.WriteLine("Result: ");
            source1
            .Detect(p => p.SingleElement(e => e.Field1 == "A")
                    .SingleElement(e => e.Field1 == "C"))
            .SubscribeToConsole();
            Console.WriteLine();

            Console.WriteLine("Regex 2: AC");
            Console.WriteLine("Result: ");
            source1
            .DefinePattern()
            .SingleElement(e => e.Field1 == "A")
            .SingleElement(e => e.Field1 == "C")
            .Detect()
            .SubscribeToConsole();
            Console.WriteLine();
            #endregion

            #region Regex: A(B*)C and accumulate a sum of Field2 for B*
            Console.WriteLine("Regex 3: A(B*)C and accumulate a sum of Field2 for B*");
            Console.WriteLine("Result: ");
            source1
            .Detect(0, p => p.SingleElement(e => e.Field1 == "A", (ev, d) => 0)
                    .KleeneStar(r => r.SingleElement(e => e.Field1 == "B", (ev, d) => d + ev.Field2))
                    .SingleElement(e => e.Field1 == "C"))
            .SubscribeToConsole();
            Console.WriteLine();

            Console.WriteLine("Regex 3: A(B*)C and accumulate a sum of Field2 for B*");
            Console.WriteLine("Result: ");
            source1
            .DefinePattern()
            .SetRegister(0)     // or .SetRegister<int>()
            .SingleElement(e => e.Field1 == "A")
            .KleeneStar(r => r.SingleElement(e => e.Field1 == "B", (ev, d) => d + ev.Field2))
            .SingleElement(e => e.Field1 == "C")
            .Detect()
            .SubscribeToConsole();
            Console.WriteLine();
            #endregion
        }