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 3300754
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:41:24+00:00 2026-05-17T20:41:24+00:00

I have not found a regexp to do this. I need to validate the

  • 0

I have not found a regexp to do this. I need to validate the “Message-ID:” value from an email. It is similar to a email address validation regexp but much simpler, without most of the edge cases the email address allows, from rfc2822

msg-id          =       [CFWS] "<" id-left "@" id-right ">" [CFWS] 
id-left         =       dot-atom-text / no-fold-quote / obs-id-left
id-right        =       dot-atom-text / no-fold-literal / obs-id-right
no-fold-quote   =       DQUOTE *(qtext / quoted-pair) DQUOTE
no-fold-literal =       "[" *(dtext / quoted-pair) "]"

Let’s say the outter <> are optional. dot-atom-text and missing definitions can be found in rfc2822

I am not proficient in regex and I prefer to use an already tested one, if exists.

  • 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-17T20:41:24+00:00Added an answer on May 17, 2026 at 8:41 pm

    As I could not find any I ended up implementing it myself. It is not a proper validation as per RFC2822 but a good enough aproximation for now:

    static String VALIDMIDPATTERN = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*";
    private static Pattern patvalidmid = Pattern.compile(VALIDMIDPATTERN);
    
    public static boolean isMessageIdValid(String midt) {
        String mid = midt;
        if (StringUtils.countMatches(mid, "<") > 1)
            return false;
        if (StringUtils.countMatches(mid, ">") > 1)
            return false;
        if (StringUtils.containsAny(mid, "<>")) {
            mid = StringUtils.substringBetween(mid, "<", ">");
            if (StringUtils.isBlank(mid)) {
                return false;
            }
        }
        if (StringUtils.contains(mid, "..")) {
            return false;
        }
        //extract from <>
        mid = mid.trim();
        //now validate
        Matcher m = patvalidmid.matcher(mid);
        return m.matches();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know a similar question has been asked but I have not found a
I have found useful regex expressions from the site, but this particular one eludes
I have looked but have not found a specific answer for changing just one
I have searched but have not found my answer. Disclaimer: I am brand new
I apologize for the newb question but have not found a solution online. I
I have searched far and wide on the Internet but have not found anything
I have looked thoroughly, but I have not found the solution (or perhaps I
Assume I have this: Regex.Replace(aa cc bbbb,aa cc,,RegexOptions.IgnoreCase); But I also need to ignore
I want to validate email address in html form. I have very little knowledge
Possible Duplicate: Is there a php library for email address validation? How to validate

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.