Attention: We are retiring the ASP.NET Community Blogs. Learn more >

ExplicitCapture - creating a pattern that can NEVER match!

Today, while reading about ExplicitCapture (page 172 of the Mastering Regular Expressions book), I learnt something totally new; that is, the following will fail:

    source:  "BBB Hello BBB"
    pattern: "BBB(?>.*?)BBB"

Which means that, whenever you want to obfuscate your regex's, you can freely throw in instances of (?>.*?).... wow! I might try to blog a bit more about ExplicitCapture in the next few days because, like \G, it's not really that obvious when you would use them.

Anyways, check out my new pattern for matching a Person's first name:

    source:   "Foo"
    pattern:  "\b\w+(?>.*?)\w*(?>.*?)(?>.*?)\b"

1 Comment

Comments have been disabled for this content.