Solved

Meaning of regular expressions

Posted on 2009-05-18
2
296 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 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…

733 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