Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5930869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:36:49+00:00 2026-05-22T14:36:49+00:00

I need to parse email files with regex in c#, that is parse the

  • 0

I need to parse email files with regex in c#, that is parse the email file that contains several emails and parse it into its constituents e.g from, to, bcc etc.

the regex am using for email is

"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

the problem am having is the To, Cc and Bcc sometimes contains more than one email, and occurs in more than one line

To: Me meagain <me@me.com>,
    Me1 meagain <me1@me.com>,Me3 meagain <me1@me.com>

Also, which regex will match the message?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:36:50+00:00Added an answer on May 22, 2026 at 2:36 pm

    Parsing an email message with regular expressions is a terrible idea. You might be able to parse the constituent parts with regular expressions, but finding the constituent parts with regular expressions is going to give you fits.

    The normal case, of course, is pretty easy. But then you run across something like a message that has an embedded message within it. That is, the content includes a full email message with From:, To:, Bcc:, etc. And your naive regex parser thinks, “Oh, boy! I found a new message!”

    You’re better off reading and understanding the Internet Message Format and writing a real parser, or using something already written like OpenPop.NET.

    Also, check out the suggestions in Reading Email using Pop3 in C# and https://stackoverflow.com/questions/26606/free-pop3-net-library, among others.

    A good example of the difficulty you’ll face is that your regular expression for matching email addresses is inadequate. According to section 3.2.4 of RFC2822 (linked above), the following characters are allowed in the “local-part” of the email address:

    atext = ALPHA / DIGIT / ; Any character except controls,
            "!" / "#" /     ;  SP, and specials.
            "$" / "%" /     ;  Used for atoms
            "&" / "'" /
            "*" / "+" /
            "-" / "/" /
            "=" / "?" /
            "^" / "_" /
            "`" / "{" /
            "|" / "}" /
            "~"
    

    The domain name can contain any ASCII except whitespace and the “\” character, and has to meet some format requirements. Then there’s the “obsolete” stuff that, although deprecated, is still in use. And that’s just in parsing email addresses. If you look at the stuff that can be included in the other fields, I think you’ll agree that trying to parse it with regular expressions is going to be frustrating at best.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need parse through a file and do some processing into it. The file
I have a rather big number of source files that I need parse and
Need to parse a file for lines of data that start with this pattern
Perl newbie here. I have a log file that I need to parse out
For some reason I need to fetch emails from /var/mail/username file. It seems like
I need to parse html emails that will be similar but not exactly the
I have a file with over 2000 lines that I need to parse. I
I need to parse a xml file which is practically an image of a
I need to parse a file but the data is in a strange format
I need to parse out the string that has following structure x:{a,b,c,}, y:{d,e,f} etc.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.