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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:43:08+00:00 2026-06-14T08:43:08+00:00

I want to write a regular expression to filter out all junk out of

  • 0

I want to write a regular expression to filter out all junk out of an email that is being pulled in through imaplib and email modules in my Python script below. I’m thinking a regex is best but feel free to suggest better solutions. Any idea why the email text has a equals in the word be=tter below? The original email has it as better.

Python snippet:

emailMessage = email.message_from_string
print emailMessage.get_payload():

Print Text:

>=20
> >>>>
> >>>> Hope this makes it through you spam filter but couldn't think of a be=
tter subject.
> >>>>
  • 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-06-14T08:43:10+00:00Added an answer on June 14, 2026 at 8:43 am

    As Karl Knechtel says in the comments, your message is encoded as quoted-printable. To decode that, use quopri.decodestring():

    import quopri
    
    decoded = quopri.decodestring(emailMessage.get_payload())
    

    Using regexes to strip out the “junk” characters is going to be inefficient, and also means that whenever a new one turns up in your input down the line, you’ll have to modify your code.

    However, if after decoding you want to lose the > characters [and any whitespace betwwen them] at the beginning of each line, then for that, a regex is a reasonable solution:

    import re
    
    chevrons = re.compile("(?m)^[> ]*")
    stripped = re.sub(chevrons, "", decoded)
    

    (?m) indicates that the regex is multiline, by the way.

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

Sidebar

Related Questions

I want to write a simple regular expression in Python that extracts a number
I want to write a regular expression in F# that represents strings which start
I want to write a regular expression that will match the following string a
Let's say I want to write a regular expression to change all <abc> ,
In C#, I want to write a regular expression that will accept only years
I want to write a regular expression that matches each word in a sentence:
I'm trying to write an expression that would filter out several types of directories
I want to write a regular expression that tests for the following, something that
I write regular expression for alphanumerics, but it is not taking space. I want
I'm trying to write a regular expression that matches the (non-javadoc) comments in the

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.