Solved

Meaning of regular expressions

Posted on 2009-05-18
2
291 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
ID: 24418180
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
ID: 24418401
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…

895 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

11 Experts available now in Live!

Get 1:1 Help Now