Python Forum
Find and Replace numbers in String
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find and Replace numbers in String
#2
Might could do something like

string = 'It was 1there...some text, some text'
for word in string:
    if word.isnumeric():
        string = string.replace(word, '')
print(string)
Output:
It was there...some text, some text
Of coarse it would be better suited to make it a function. This will remove all numbers.
rob101 likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Find and Replace numbers in String - by giddyhead - Jul-16-2022, 10:39 PM
RE: Find and Replace numbers in String - by menator01 - Jul-16-2022, 11:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to replace a string with a file (HTML file) tester_V 1 795 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  Pulling Specifics Words/Numbers from String bigpapa 2 792 May-01-2023, 07:22 PM
Last Post: bigpapa
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,587 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,295 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  Replace string in a nested Dictianory. SpongeB0B 2 1,243 Mar-24-2023, 05:09 PM
Last Post: SpongeB0B
  Working with Excel and Word, Several Questions Regarding Find and Replace Brandon_Pickert 4 1,607 Feb-11-2023, 03:59 PM
Last Post: Brandon_Pickert
  Replace with upper(string) WJSwan 7 1,625 Feb-10-2023, 10:28 AM
Last Post: WJSwan
  Find numbers using Regex giddyhead 18 3,240 Jul-28-2022, 12:29 AM
Last Post: giddyhead
  find 2 largest equal numbers Frankduc 13 3,646 Jan-11-2022, 07:10 PM
Last Post: Frankduc
  Replace String in multiple text-files [SOLVED] AlphaInc 5 8,227 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020