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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:28:33+00:00 2026-06-12T18:28:33+00:00

I have a Python string containing information that I want to pull out using

  • 0

I have a Python string containing information that I want to pull out using regex.

Example:

"The weather is 75 degrees with a humidity of 13%"

I want to just pull out the “75” and the “13.” Here is what I’ve tried so far in Python.

import re

str = "The weather is 75 degrees with a humidity of 13%"
m = re.search("The weather is \d+ degrees with a humidity of \d+%", str)
matched = m.group()

However, this obviously matches the entire string instead of just the parts I want. How do I pull out just the numbers that I want? I’ve looked into backreferences but it seems to only apply to within the regex pattern itself.

  • 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-12T18:28:35+00:00Added an answer on June 12, 2026 at 6:28 pm
    m = re.search("The weather is (\d+) degrees with a humidity of (\d+)%", str)
    matched = m.groups()
    

    you need to wrap what you want in parenthesis …

    >>> s1 = "The weather is 75 degrees with a humidity of 13%"
    >>> m = re.search("The weather is (\d+) degrees with a humidity of (\d+)%", s1)
    >>> m.groups()
    ('75', '13')
    

    or just use findall to just get the numbers out of any string

    >>> re.findall("\d+",s1)
    ['75', '13']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using python, and I want a function that takes a string containing a
I want to find the last modified file that contains a string using python.
I have a server side Python script that returns a JSON string containing parameters
I have some code in a python string that contains extraneous empty lines. I
i have string stored in python variables, and i am outputting a html that
I am using Python 2.7 . I have an alphanumeric string, on which I
Say I have a string containing foobar fooBAR FOObar FOOBAR , and I want
I have a file containing python's object as string, then i open it and
I have two python dictionaries containing information about japanese words and characters: vocabDic :
In a Python package, I have a string containing (presumably) the name of a

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.