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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:05:15+00:00 2026-06-17T12:05:15+00:00

I am new to Python and I do not know regular expressions in Python.

  • 0

I am new to Python and I do not know regular expressions in Python. Here is the question. I have a sentence like “Total Cost: 37” in stdout, I want to extract the cost info which is 37. When I match the words “Total Cost: ” in a specific line how should I get the rest of the line which is the info that I am interested in?

  • 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-17T12:05:16+00:00Added an answer on June 17, 2026 at 12:05 pm

    use regex:

    Total Cost:\s? explanation:

    “Total Cost”: Match the literal Total Cost:

    \s? : 1 to 0 times Whitespace [\t \r\n\f]

    Capturing group ([-+]?\d+):

    [-+]?: 1 to 0 times matches one of the following chars: -+

    \d+ :infinite to 1 times Digit [0-9]

    In [121]: strs="some text Total Cost: 37 some more more Total Cost: -100"
    
    In [122]: re.findall(r"Total Cost:\s?([-+]?\d+)",strs)
    Out[122]: ['37', '-100']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to Python, have a simple, situational question: Trying to use BeautifulSoup to parse
I am new to python and I do not know how to go about
new to python. so i have this function, and I don't know how to
Relatively new to Python.. I would like to know how to check if a
I am new to Python and I do not know why but the if
I'm very new to python so I have very simple doubt. Here is my
I'm relatively new to wxPython (but not Python itself), so forgive me if I've
I'm new to Python's iterators, so maybe my language is not always correct. I
First, I'm not a python programmer. I'm an old C dog that's learned new
I'm new to subprocess module of python, currently my implementation is not multi processed.

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.