Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Add number to numbers inside a text python:
Input: Sono stata 21 commossa che lei ci ha 45 letto
Sono stata 21 commossa che lei ci ha 45 letto
Output: Sono stata 22 commossa che lei ci ha 46 letto
Sono stata 22 commossa che lei ci ha 46 letto
My code: text_after = re.sub("^[0-9]+", "^[0-9]+"+1, text)
text_after = re.sub("^[0-9]+", "^[0-9]+"+1, text)
re.sub
re.sub(r'\d+', lambda x: str(int(x.group())+1), s)
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
re.subwith a callable as replacement argument.re.sub(r'\d+', lambda x: str(int(x.group())+1), s). See ideone.com/dX1C96