?
Solved

Meaning of regular expressions

Posted on 2009-05-18
2
Medium Priority
?
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Accepted Solution

by:
David S. earned 2000 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

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Suggested Courses

762 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