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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:14:06+00:00 2026-05-25T02:14:06+00:00

I receive similar emails from multiple senders and use regular expressions m and n

  • 0

I receive similar emails from multiple senders and use regular expressions m and n below to pull out needed strings. That part is working fine.

Regular expression o however is what has me confused. The text file I am reading is a combination of 9 email messages saved to one text file and opened in Python as a string. Original Sender (regex o) occurs at the beginning of each new message in the file (9 times)

I want to write the same Original Sender after each CUSIP and NAME found until a different Original Sender is matched.

I am using xlwt3 and wincom32.

Sample from the text file with combined emails which is very standard:

--- Original Sender: TOM MADEUPNAME, SOME BANK, N. ---
----- Original Message -----
From: TOM MADEUPNAME (SOME BANK, N.)
To: BOB THISISMYEMAIL (XYZ INVESTMENTS, INC)
At:  8/31  8:53:25
**Offerings**

Mezz ReRemics
Cusip      Description       Original Current Cashflow Collat Offering
05531UAB6  BCAP 2009-RR5 1A2   18,745  18,745 Snr Sup  Fxd      45.000

Prime/Alt-A Fixed
Cusip      Description       Original Current Cashflow Collat Offering
059487AE8  BOAA 2006-6 CB5     25,940  14,350 Seq      Fxd      83.000
12544XAX3  CWHL 2007-9 A13     10,190  10,190 Ssnr Nas Fxd      92.500
17312XAJ3  CMSI 2007-4 1A9      2,871   2,741 Spr Snr  Fxd      86.000

--- Original Sender: JOE MADEUPNAME, EUROPEAN BANK SECURI ---
----- Original Message -----
From: JOE MADEUPNAME (EUROPEAN BANK SECURI)
To: BOB THISISMYEMAIL (XYZ INVESTMENTS, INC)
At:  8/31  8:20:16

8-31-2011 

Alt-A Fixed
Bond            O/F    C/F    Cpn  FICO CAL WALB  60+    Notes             Offer
CSMC 06-9 7A1   25.00  11.97  L+45  728  26  578  35.21  FLT,AS,0.0%       50-00
LXS 07-10H 2A1  68.26  34.01  L+16  744   6  125  33.98  SS,9.57%          42-00
CSMC 06-7 9A1   15.00   7.81  L+30  688   5  198  46.46  SS,0.0%           29-16

Prime Hybrid 
Bond            O/F     C/F   Cpn  FICO CAL WALB  60+    Notes             Offer
SARM 05-18 6A1  14.56   6.01  2.58  730  46  432  15.87  SEA,SS,5/1,12.3%  78-00

Alt-A Hybrid
Bond            O/F    C/F    Cpn  FICO CAL WALB  60+    Notes             Offer
ARMT 05-12 2A1  23.78  10.71  3.07  712  48  556  35.32  SS,5/1,4.9%       *SOLD

Option Arm
Bond                O/F    C/F   Cpn  FICO CAL WALB  60+    Notes          Offer
DBALT 07-OA4 1A1B  10.00   7.25  L+13  716  63  562  47.17  SS,OC,42.2%    64-16
--------------------------------------------------------------------------------------

Updated – working

count_cusip = 0
count_name = 0
count_sender = 0 
cur_sender = ''
for line in lines:

    o = re.search(r"Original Sender:\s\b\w+\s\w+", line)
    if o:
        count_sender += 1
        ws.write(count_sender,2,o.group(0))
        ws.write(count_sender,2,cur_sender)
        cur_sender = o.group(0)

    m = re.search('[0-9]{3}[a-zA-Z0-9]{6}', line)
    if m:
        count_cusip += 1
        ws.write(count_cusip,0,m.group(0))
        ws.write(count_cusip,2,cur_sender)

    n = re.search('[A-Z]{3,5}\s[0-9]{1,4}\D{1,3}\S{1,3}\s{1,2}\w+', line)
    if n:
        count_name += 1
        ws.write(count_name,1,n.group(0))
        ws.write(count_cusip,2,cur_sender)

        o = re.search(r"Original Sender:\s\b\w+\s\w+", line)
        if o:
            cur_sender = o.group(0)

        ws.write(count_name,2,cur_sender)

Updated Output – as desired.

CUSIP   Bond Name           Original Sender
00442PAD2   ACE 2006-OP1 A2B        Original Sender: Nick Madeupname
12557YAE7   ARMT 05-12 2A1          Original Sender: Bobby Madeupname
39153VAT1   CSMC 06-9 7A1           Original Sender: Bobby Madeupname
05377RAE4   LXS 07-10H 2A1          Original Sender: Jane Madeupname
02005HAF0   CSMC 06-7 9A1           Original Sender: Jane Madeupname
  • 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-25T02:14:07+00:00Added an answer on May 25, 2026 at 2:14 am

    Your question isn’t completely clear since you didn’t show an output sample, but here’s an educated guess:

    count_cusip = 0
    count_name = 0
    count_sender = 0 
    cur_sender = ''
    for line in lines:
    
        m = re.search('[0-9]{3}[a-zA-Z0-9]{6}', line)
        if m:
            count_cusip += 1
            ws.write(count_cusip,0,m.group(0))
            ws.write(count_cusip,2,cur_sender)
    
        n = re.search('[A-Z]{3,5}\s[0-9]{1,4}\D{1,3}\S{1,3}\s{1,2}\w+', line)
        if n:
            count_name += 1
            ws.write(count_name,1,n.group(0))
            ws.write(count_name,2,cur_sender)
    
        o = re.search(r"Original Sender:\s\b\w+\s\w+", line)
        if o:
            count_sender += 1
            cur_sender = o.group(0)
    

    Rather than writing the Original Sender when encountered, you need to save it and write the current value for each cusip and name.

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

Sidebar

Related Questions

I occasionally receive emails from Google ( accounts-noreply@google.com ), similar to the following: Subject:
I receive a date in the format below from a json file. Im not
I have a requirement that my app, can receive events (e.g. messages) from server
I have noticed that certain SMS messages that I receive from companies come with
I receive messages from a Google Talk account, they are shown in the Table
I receive a string from a database query, then I remove all HTML tags,
We receive 5-10 improvement requests each day from our customers. Some of them are
I followed this tutorial to send emails from rails and it works just fine.
I'm working on an application that allows users to send and receive messages. The
I receive a complex JSON from the server. Let it be next: var data

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.