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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:36:38+00:00 2026-05-18T02:36:38+00:00

i have data of thousand records which i read line by line . Each

  • 0

i have data of thousand records which i read line by line . Each line has some fields and their value but field names contain a non ascii character, below is the example of such a record :

|              |   | X:720                      | N°227: Done

where X and N°(non ascii character) are fieldnames and 720,227 and “Done” are field values which i have to extract.
These fields are optional which may exist or may not .
Now I have to check whether these fields exist in line or not and if it exists then what is its value(for example X field is having value 720 and N° is having value 227 and “Done”)
Please let me know how to do this using regex in python ,is there any another way to do this in python?

  • 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-18T02:36:38+00:00Added an answer on May 18, 2026 at 2:36 am

    Sometimes regex is good for such thing, sometimes split() and other string method will be easier. It is up to you to chose:

    #!/usr/bin/env python
    # -*- coding: utf8 -*-
    
    import re
    RE_TXT = re.compile(r'\|\s*X:(\S+)\s*\|\s*N\D*(\d+):\s*(.*)$')
    txt = '|              |   | X:720                      | N°227: Done'
    rx = RE_TXT.search(txt)
    if rx:
        print(rx.group(1))
        print(rx.group(2))
        print(rx.group(3))
    
    print('-' * 20)
    
    # other way without regex, but with more complicated logic:
    arr = [s.strip() for s in txt.split('|')]
    if arr[3].startswith('X:'):
        print(arr[3].split(':')[1])
        N, state = arr[4].split(':')
        N = N[3:]
        state = state.strip()
        print(N)
        print(state)
    

    As for regexp:

    • \s* is zero or more white characters
    • \S+ is one or more non white character
    • \d is for digits
    • \D is for non digits
    • . means any character
    • r before string means “raw” string so you do not need to escape backslash
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data from travel diaries which has been read in from a csv
I have thousands of data points and each data point has 50 dimensions. I
I have an application which is receiving data for thousands (say 50,000) subjects. Each
I have a jqgrid where the database table has a few thousand rows, but
So I have an app which needs to read a lot of small data
I have a table in MS Access, which has the following data to be
I have to store data of thousand of records in a data table and
I have few thousands of records with few 100 fields in a MySQL Table.
I currently have a listing of data that has a randomly generated order listing.
I have two MySQL databases with identical table structure, each populated with several thousand

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.