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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:41:05+00:00 2026-05-30T02:41:05+00:00

I am working on a python function. I have a given string and I

  • 0

I am working on a python function. I have a given string and I need to find if there is a number on that string, and then add 1 to that number. (any number from 1 to 100).

I found the “find”, or the “count” function but what they do (as I understand) is to find a specific letter or number. On my function, I dont know which number I am looking for, so I dont know how to use those functions.

Example 1:

# WHAT I HAVE    
string = "STRING 2"
# WHAT I WANT AS A RESULT
STRING 3

Example 2:

# WHAT I HAVE
string = "STRING 9 STRING"
# WHAT I WANT AS A RESULT
STRING 10 STRING

Does anyone knows how to do this?
Thanks 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-05-30T02:41:06+00:00Added an answer on May 30, 2026 at 2:41 am
    import re
    
    def increment_repl(match):
        return str(int(match.group(0)) + 1)
    
    def increment_ints(s):
        return re.sub(r'-?\d+', increment_repl, s)
    
    >>> increment_ints("STRING 2")
    'STRING 3'
    >>> increment_ints("STRING 9 STRING")
    'STRING 10 STRING'
    >>> increment_ints("-1 0 1 2")
    '0 1 2 3'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working in Python. I have a function that reads from a queue and creates
I need to have an at-home project now that I'm working on Python/Django at
Working in python 2.7. I have an argument that takes a list, adds the
I have a project I am working on that is written in Python. The
i am working on a regex match function in python. i have the following
I have a working python 2.7 program that calls a DLL. I am trying
Working with Python in Emacs if I want to add a try/except to a
I have recently been working with Python using Komodo Edit and other simpler editors
I'm working on a Python library that interfaces with a web service API. Like
I'm working on a Python package named lehmer that includes a bunch of extension

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.