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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:07:55+00:00 2026-05-30T23:07:55+00:00

Some file(file.dat) #####Start#### sometext sometext From: email@address.net some text some text ####End##### 1 import

  • 0

Some file(file.dat)

#####Start####
sometext
sometext
From: email@address.net
some text
some text
####End#####

1

import re
for line in open('file.dat'):
    _mail=re.search(r"\w+@\w+\.\w{2,4}").group()
print(type(_mail))

Out: ‘NoneType’

2

import re
for line in open('file.dat'):
    if(re.match(r"From:.*",line)):
        _mail=re.search(r"\w+@\w+\.\w{2,4}").group()
print _mail

Out: email@address.net

Explain me, please. Why can’t I use first way?

  • 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-30T23:07:56+00:00Added an answer on May 30, 2026 at 11:07 pm

    Your first try will search the mail pattern in each line. The variable _mail will contain, at the end of the loop, the LAST result of re.search (well, the result of re.search on the last line in the file, to be more precise).

    So your result will be overwritten.

    If you want to use the first way, you have to add:

    if _mail: break
    

    To end the loop

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

Sidebar

Related Questions

I got some file sample.mt from client, and when i open info, it reveals
I have a dat file containing data. A line from the file is as
I need to do some work with a backup WSS .dat file and I'm
I am planning to use Maxmind's DAT file to provide some basic geolocation capabilities
I have some data to export from DB and save as CSV file, and
I'm trying to read a file then append some text to a certain place
I am having trouble with some file IO stuff. I have this file: db.dat:
I have a dat file with some data in it seperated by '|' character.
I am trying to open a .dat file in Excel, which is tab delimited,
I am using PHP to pass some information in a text file back to

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.