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

  • Home
  • SEARCH
  • 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 3392970
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:59:43+00:00 2026-05-18T03:59:43+00:00

Text File contents: &CRB A=’test1′ B=123,345, 678 &END Misc text potentially between entries …

  • 0

Text File contents:

&CRB  A='test1'   B=123,345, 678   &END
Misc text potentially between entries ...
&CRB  A='test2'   
             B=788, 345, 3424   &END
&CRB  A='test3'   
             B=788, 345, 3424   &END
&CRB  A='test4' B=788, 345, 3424   &END

What is the most efficient way to iterate through the entries between the keywords? Note
that some entries span lines. Something like the following is desired –

f = open(filename)
for entry in f:
    - do something with entry

Of course it is not that easy. But, are there suggestions on a straightforward way to iterate thorough the entries delimiated by two key words.

  • 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-18T03:59:44+00:00Added an answer on May 18, 2026 at 3:59 am

    Assuming that the entry is all of the text between &CRB and &END pairs, you can pull out the text between them with something like this:

    import re
    
    # the regular expression treats newlines as a regular character, so the
    # multiline entries are okay. It's non-greedy, so it gets individual entries.
    pat = re.compile(r'&CRB(.+?)&END',  re.DOTALL)
    
    s = ''' &CRB  A='test1'   B=123,345, 678   &END
    Misc text potentially between entries ...
    &CRB  A='test2'   
                 B=788, 345, 3424   &END
    &CRB  A='test3'   
                 B=788, 345, 3424   &END
    &CRB  A='test4' B=788, 345, 3424   &END'''
    
    for entry in pat.findall(s):
       # do something with each entry
       print entry
    

    prints this:

     A='test1'   B=123,345, 678   
      A='test2'   
                 B=788, 345, 3424   
      A='test3'   
                 B=788, 345, 3424   
      A='test4' B=788, 345, 3424  
    

    …it’s your problem to clean up and interpret the contents of each of those records…

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

Sidebar

Related Questions

I have a text file named num.txt who's only contents is the line 123
How do you display the contents of a text file in a TextArea when
I am planning to extract the contents from a text file named itest.txt that
I would like to read a text file and input its contents into an
I'm trying to read the contents of a small text file using the common
I've got the entire contents of a text file (at least a few KB)
Supposed a text file named name.txt . there are some contents as the following
I am trying to match the text contents(character data) of an XML file with
I have some simple text file. I am trying to read that file contents
I'm wondering how I could delete all contents in a text file using VB6

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.