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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:35:07+00:00 2026-06-11T06:35:07+00:00

I have a textfile that consists of multiple blocks such as one shown here

  • 0

I have a textfile that consists of multiple blocks such as one shown here :

TestVar 00000000  WWWWWW 222.222 222.222 222.222
UNKNOWN ,,,,,,,,  ,,,,,,  ,,,,,,

I would like to get the folowing output:
Each part is always 8 characters long (e.g TestVar , 00000000)
From each line that start with testvar i would like the code to return:

WWWWWW_00000000

Can someone help me with this I have used regex before but never with python and am quite new to both of them.

Thanks

  • 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-11T06:35:09+00:00Added an answer on June 11, 2026 at 6:35 am

    With regex pattern ^TestVar\s+(\d{8})\s+(\S+) you can get that as >>

    import re
    p = re.compile('^TestVar\s+(\d{8})\s+(\S+)')
    m = p.match('TestVar 00000000  WWWWWW 222.222 222.222 222.222')
    if m:
        print 'Match found: ', m.group(2) + '_' + m.group(1)
    else:
        print 'No match'
    

    Test this demo here.


    To find all occurrences in multiline input string use:

    p = re.compile("^TestVar\s+(\d{8})\s+(\S+)", re.MULTILINE) 
    m = p.findall(input) 
    

    To learn more about regex with Python, see http://docs.python.org/howto/regex.html

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

Sidebar

Related Questions

I have a textfile that I am I want to make into a list.
I have a C#-Application that stores data from a TextFile in a Dictionary-Object. The
I need to copy multiple files from a directory using a textfile that doesnt
I have a Perl one-liner that works fine on the command line: perl -nle
I have a textfile that contains authors and the books written by authors. I
I have a textfile, that is loaded into a swf through a flashvars: The
I have a textfile (.txt) on a server. It contains only one word i.e.
I am building an android application that reads text files. Now,i have multiple text
I have a regular expression that has several matches in a textfile. I want
I have been given a textfile which contains data on time sheet. That line

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.