Solved

Meaning of regular expressions

Posted on 2009-05-18
2
290 Views
Last Modified: 2013-12-17
To all regexp expert out there, I'd like to request for insight of what following regexp would do (or at least how I can unravel it part-by-part). I understand it's trying to validate the inputStr, but I'm totally clueless as to what the pattern allows or doesn't allow. I'm regexp newbie, so a pattern this long is beyond my comprehension. All help is much appreciated.

string pattern = @"^(([^<>()[\]\\.,;:\s@\""]+"

      + @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@"

      + @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"

      + @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"

      + @"[a-zA-Z]{2,}))$";

System.Text.RegularExpressions.Regex regExp = new System.Text.RegularExpressions.Regex(pattern);

if (!regExp.IsMatch(inputStr))

{

  //...

}

Open in new window

0
Comment
Question by:philipjonathan
2 Comments
 
LVL 42

Accepted Solution

by:
David S. earned 500 total points
Comment Utility
It's checking for valid email addresses.  It allows both IP addresses and domain names for the "domain part" of the address.  Also it doesn't overly restrict the "local part" of the address like many regexp validators that people write tend to do.

This is a great reference site for regexp: http://www.regular-expressions.info/tutorial.html
0
 
LVL 18

Author Comment

by:philipjonathan
Comment Utility
Thanks Kravimir, both for the analysis and the great site. I managed to break down the regex with Expresso, and trying various email addresses on it. I'm playing around with it, and will post again for follow up. Thanks!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now