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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:33:51+00:00 2026-06-06T23:33:51+00:00

Suppose I had a string string1 = 498results should get Now I need to

  • 0

Suppose I had a string

string1 = "498results should get" 

Now I need to get only integer values from the string like 498. Here I don’t want to use list slicing because the integer values may increase like these examples:

string2 = "49867results should get" 
string3 = "497543results should get" 

So I want to get only integer values out from the string exactly in the same order. I mean like 498,49867,497543 from string1,string2,string3 respectively.

Can anyone let me know how to do this in a one or two lines?

  • 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-06T23:33:53+00:00Added an answer on June 6, 2026 at 11:33 pm
    >>> import re
    >>> string1 = "498results should get"
    >>> int(re.search(r'\d+', string1).group())
    498
    

    If there are multiple integers in the string:

    >>> map(int, re.findall(r'\d+', string1))
    [498]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I had a string for example: >>> stri = "日本" >>> res =
Suppose I had a WCF service that I have coded up, like Clemens Vasters's
Suppose you had code like this: _READERS = None _WRITERS = None def Init(num_readers,
Suppose I only had the regular J2SE http libraries but wanted to write a
Suppose I'm making a JDBC call and I had fetched data from a database
Suppose I had a string, cats cats cats and dogs dogs dogs. What regular
I need to pass a url string from the view to the controller, a
Suppose I had the following class: template<typename T> class Value { public: Value(std::string name,
I had create a class named ChannelObj that contains values like this public class
Till now I had been using following code to ftp file from one location

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.