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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:19:17+00:00 2026-06-04T22:19:17+00:00

I have a problem with python regex. The result seems fine on regxe buddy,

  • 0

I have a problem with python regex. The result seems fine on regxe buddy, but fails in python.

Set of data i have to match is a list:

['  101  0.  0.\n',
 '  0.  100.\n',
 '  1.  98.5107805\n',
 '  2.  97.0464459\n',
 '  3.  95.6065328\n', ... ]

I have to get all the numbers starting from second line.
For this i used:

pattern = compile(r'\s*(?P<raw_time>\d*\.?\d*)\s+(?P<raw_value>\d*\.\d*)')

And all worked fine. I iterate through the list and get the first value in “raw_time” and second one in “raw_value” for every line.
Then i was supposed to expand the term to also work with weighted data.

So the data turned to:

['  101  0.  0.\n',
 '  0.  100.  1\n',
 '  1.  98.5107805  1\n',
 '  2.  97.0464459  1\n',
 '  3.  95.6065328  1\n', ... ]

I still just have to parse out two first parameters. So i changed the pattern to:

pattern = compile(r'\s*(?P<raw_time>\d*\.?\d*)\s+(?P<raw_value>\d*\.\d*).+')

It works fine all lines except the 1.

Working:

In [35]: pattern.search('1.  98.5107805  1\n').groupdict()
Out[35]: {'raw_time': '1.', 'raw_value': '98.5107805'}

Working:

In [37]: pattern.search('  0.  100.  1\n').groupdict()
Out[37]: {'raw_time': '0.', 'raw_value': '100.'}

Working:

In [44]: pattern.search(‘1. 98.5107805\n’).groupdict()
Out[44]: {‘raw_time’: ‘1.’, ‘raw_value’: ‘98.510780’}

Not working:

In [46]: pattern.search('  0.  100.\n').groupdict()
Out[46]: {'raw_time': '', 'raw_value': '0.'}

I heavily rely on regex (sure, demo, but it was consistent with python till now).

Advice?

tnx

  • 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-04T22:19:18+00:00Added an answer on June 4, 2026 at 10:19 pm

    The .+ that you’ve added needs to be changed to .*.

    The + operator requires at least one character, whereas * will accept zero or more.

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

Sidebar

Related Questions

I have problem with list in python. here is the simple codes: x =
I have a problem. I'm trying to use urllib library in python. but, I
I'm new to python programming. I have this problem: I have a list of
I have problem concerning python packages and testing. I'm writing an application using wx
I have a problem in Python. How can I increment by one fully automatically
I have a problem of upgrading python from 2.4 to 2.6: I have CentOS
I have a problem with my python code. I am writing a GUI in
I have a problem with using Twisted for simple concurrency in python. The problem
I have a problem with initialzing a 2D array in python. I want a
I have wrote following code for a simple problem in Python - def Peu1(numbers):

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.