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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:08:07+00:00 2026-06-01T00:08:07+00:00

I might have pretty basic question about regex. I have the following regex, which

  • 0

I might have pretty basic question about regex. I have the following regex, which when hardcoded int the application work fine, but then I read it with ConfigParser doesn’t seem to work:

r"\[[+-]?\d+(?:\.\d+)?\]"

The way how I read it is :

Config = ConfigParser.ConfigParser()
Config.read("test.conf")
test_regex = Config.get("test","test_regex")
search_pattern = re.compile(test_regex)

test_result = search_pattern.findall(text_to_parse)

The part of the test.conf

[test]
test_regex=r"\[[+-]?\d+(?:\.\d+)?\]"

The input for testing might be something as follows:

text_to_parse = " Here is the [TEST-DONE]" // Success: my regex is extracting [TEST-DONE]
text_to_parse = " Here is the some text" // Failure my regex returns empty list

Any solution for this issue?
Thanks a lot,
Serhiy.

EDIT: was my attention error, as I mention in the comment to answer, but the solution of remotion of the r from regex when it’s in the file helped a lot.

  • 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-01T00:08:09+00:00Added an answer on June 1, 2026 at 12:08 am

    You can use ast.literal_eval to parse the string according to the Python rules:

    >>> import ast
    >>> ast.literal_eval(conf.get("test", "test_regex"))
    '\\[[+-]?\\d+(?:\\.\\d+)?\\]'
    

    But it’s easier to just change your config file to contain the unescaped regex in the first place:

    [test]
    test_regex=\[[+-]?\d+(?:\.\d+)?\] 
    
    >>> conf.get("test", "test_regex")
    '\\[[+-]?\\d+(?:\\.\\d+)?\\]'
    

    That said, the regex doesn’t seem to do what you think it does. It matches:

    • opening bracket
    • followed by optional + or – sign
    • followed by a number of digits
    • optionally followed by a dot and more digits
    • followed by closing bracket

    Example:

    >>> re.findall(r'\[[+-]?\d+(?:\.\d+)?\]', 'foo [+10] bar [-3.5]')
    ['[+10]', '[-3.5]']
    

    Of course there will not be any matches in both of your example strings, because they don’t contain the pattern!

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

Sidebar

Related Questions

I have created a custom even class which is pretty basic. But when calling
This might be a pretty basic question, or peculiar to my set up (hopefully
I am working on a pretty basic C# visual studio forms application but am
I know this is a pretty basic question, but I don't know how to
curious if anyone might have some insight in how I would do the following
I think it might have been asked before but i was unable to find
I believe this question might have been previously attempted in 2006 on a different
I guess this is going to sound like a pretty basic question to any
I come from Windows .Net forms development. This is a pretty basic/fundamental question. I'm
I know this question might be repeated many times but would really appreciate any

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.