Jul-24-2022, 12:11 PM
(This post was last modified: Jul-24-2022, 02:16 PM by Yoriz.
Edit Reason: Formatting
)
(Jul-24-2022, 06:26 AM)rob101 Wrote: Hi.
Does this do what you want?
import re string = '1the 5one 5529care 30over' for i in range(len(string)): digit = re.search('[0-9]', string[i]) if digit: print(f'Found digit {string[i]} at position {i}'){edit to remove my debug line of code}
Output:Found digit 1 at position 0 Found digit 5 at position 5 Found digit 5 at position 10 Found digit 5 at position 11 Found digit 2 at position 12 Found digit 9 at position 13 Found digit 3 at position 19 Found digit 0 at position 20
Hi,
Thanks for the reply with information and help. Unfortunately it finds all the numbers within. The numbers in bold below is what I am looking to get rid of. The following is a sample but contains the format of the text in one of the lists which contain numbers throughout:
Hope it clarifies. Thanks in advance.
25 - not this number
the cow just over the moon and the sun is in 1the sky
26 - not this number
5one day is soon and soon is near take 5529care, 30over and out
59 - not this number
The covers at near the back of the 59closet, and when found have them place on the each of the beds. However you see the pillow cases use the ones on the 9second shelve.
(Jul-24-2022, 07:29 AM)Pedroski55 Wrote: Maybe like this?
import re mylist = ['1the', '5one', '5529care', '30over', '55more66'] # re.findall returns a list for s in mylist: result = re.findall('[0-9]+', s) print(s) print(result)
Hey,
Thanks for the help. Unfortunately due to numbers spread throughout each list it finds all the numbers. Looking to only find the numbers attached to words in bold. I have included a sample list for reference.
Thanks
25 - not this number
the cow just over the moon and the sun is in 1the sky
26 - not this number
5one day is soon and soon is near take 5529care, 30over and out
59 - not this number
The covers at near the back of the 59closet, and when found have them place on the each of the beds. However you see the pillow cases use the ones on the 9second shelve.