Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex Pattern
#1
Hi,

I have two patterns in my code, one to remove the first part of the string which is just garbage, the second is to remove extra newlines in the string, but all of them are not working, please help.

import re
import string

Email = '''

<!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:"Minion Pro";}
@font-face
	{font-family:inherit;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
h4
	{mso-style-priority:9;
	mso-style-link:"Heading 4 Char";
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	font-size:12.0pt;
	font-family:"Calibri",sans-serif;}
h5
	{mso-style-priority:9;
	mso-style-link:"Heading 5 Char";
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	font-size:10.0pt;
	font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
span.Heading4Char
	{mso-style-name:"Heading 4 Char";
	mso-style-priority:9;
	mso-style-link:"Heading 4";
	font-family:"Calibri",sans-serif;
	font-weight:bold;}
span.Heading5Char
	{mso-style-name:"Heading 5 Char";
	mso-style-priority:9;
	mso-style-link:"Heading 5";
	font-family:"Calibri",sans-serif;
	font-weight:bold;}
p.msonormal0, li.msonormal0, div.msonormal0
	{mso-style-name:msonormal;
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	font-size:12.0pt;
	font-family:"Times New Roman",serif;}
span.3oh-
	{mso-style-name:_3oh-;}
span.EmailStyle21
	{mso-style-type:personal-reply;
	font-family:"Calibri",sans-serif;
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
	{page:WordSection1;}
-->

<!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
h4
	{mso-style-priority:9;
	mso-style-link:"Heading 4 Char";
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	font-size:12.0pt;
	font-family:"Calibri",sans-serif;}
h5
	{mso-style-priority:9;
	mso-style-link:"Heading 5 Char";
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	font-size:10.0pt;
	font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:#954F72;
	text-decoration:underline;}
span.Heading4Char
	{mso-style-name:"Heading 4 Char";
	mso-style-priority:9;
	mso-style-link:"Heading 4";
	font-family:"Calibri",sans-serif;
	font-weight:bold;}
span.Heading5Char
	{mso-style-name:"Heading 5 Char";
	mso-style-priority:9;
	mso-style-link:"Heading 5";
	font-family:"Calibri",sans-serif;
	font-weight:bold;}
span.3oh-
	{mso-style-name:_3oh-;}
.MsoChpDefault
	{mso-style-type:export-only;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
	{page:WordSection1;}
-->

Hi

Will do thanks

Boss King
Content Publisher 

T. 555-666-777/ M. 555-666-777




From: [email protected];
Sent: Monday, January 28, 2019 12:37:13 PM
To: Team
Subject: RE: Let them know




Hi Iron man,

We can confirm the mission had been cancelled on 25/01/2019
Any contacts made there after should be ignored.

You may notify Me they are persisting

Thank you.


Kind Regards/Vriendelike Groete.






























Iron Man




Client Care Media Manager




Client Care/Kliente Diens









T: #43;27 21915 7556
|
 E: [email protected]













Personal
|
Commercial
|
Specialist
 | Agriculture










From: Almene Barends lt;[email protected];

Sent: 28 January 2019 12:04 PM
To: [email protected];
Subject: Mission



Hi team, please can you assist with this service escalation -client been repeatedly emailed us to cancel her policy
I have requested an email address, do we have another one on file as she is overseas

Thanks







THU 9:48 AM














Good day, I have been emailing for three days to try and stop/cancel my policy as I have immigrated and the house has bee sold.
 And every other department responds except for the one that actually NEEDS to do it! 90421050084








FRI 2:05 PM






Have a nice day


Hi Claire, thank you for bringing this to our attention. 







James Bond
Content Publisher 

T. 555-666-777 / M. 555-666-777



The content of this email is confidential and intended for the addressee only. If it was sent to you in error, please notify the sender immediately and delete the email. 



image003.jpgimage/[email protected]:37:13truefalseimage004.jpgimage/[email protected]:37:13truefalseimage005.jpgimage/[email protected]:37:13truefalse396972019-01-28T10:45:35Z2019-01-28T10:45:47ZfalsefalsedigitalSMTPOneOffMarguerite


'''

pattern = re.compile(r'<!--.*-->')
text = pattern.sub('', Email).strip()
remove_white_space = re.sub(r'\n\n]{1,}', '\n\n', text)
print(remove_white_space)
print(text)
Reply


Messages In This Thread
Regex Pattern - by NewBeie - May-07-2019, 07:44 AM
RE: Regex Pattern - by Gribouillis - May-07-2019, 09:38 AM
RE: Regex Pattern - by snippsat - May-07-2019, 02:06 PM
RE: Regex Pattern - by michalmonday - May-08-2019, 11:50 AM
RE: Regex Pattern - by NewBeie - May-13-2019, 05:48 AM
RE: Regex Pattern - by michalmonday - May-13-2019, 01:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Regex pattern match WJSwan 2 2,999 Feb-07-2023, 04:52 AM
Last Post: WJSwan
  regex pattern to extract relevant sentences Bubly 2 2,775 Jul-06-2021, 04:17 PM
Last Post: Bubly
  Reading a Regex pattern stahorse 12 7,779 Apr-25-2019, 10:21 AM
Last Post: NewBeie
  Regex, creating a pattern stahorse 5 4,368 Apr-24-2019, 08:29 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020