Welcome to WindowsClient.net | Sign in | Join

Zuker On Foundations

The realm of .NET (WPF, WCF and all around)

LINQ To Regex

Via this post by Roy Osherove.

A nice approach for working against regular expressions.
I must admit, it looks as if it would take some time to master and love.

Nice to know it's out there :)

  [Test]

        public void FindEmailUsingPattern()

        {

            var query = from match in

               RegexQuery.Against("sdlfjsfl43r3490r98*(*Email@somewhere.com_dakj3j")

                        where match.Word.Repeat.AtLeast(1)

                            .Literal("@")

                            .Word.Repeat.AtLeast(1)

                            .Literal(".")

                            .Choice.Either(

                                 Pattern.With.Literal("com"),

                                 Pattern.With.Literal("net"))

                            .IsTrue()

                        select match;

            foreach (var match in query)

            {

                Assert.AreEqual("Email@somewhere.com",match.Value);

            }

        }

Posted: May 10 2008, 06:25 PM by zuker | with no comments
Filed under: ,

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

Page view counter