Mar-16-2021, 01:40 AM
Hi I am a new python learner, having some difficulty with regular expressions
Here is the result: ['19','456','20']
I was doing some testing looking to understand regular expressions, I wrote the code and I thought it would not retrieve any numbers. When I run the code, why does it retrieve them? The way I wrote it, I thought that if a number is not followed by another number it wouldn't be retrieved.
Do I understand this correctly: "is 1 a number? yes. is 9 a number? yes. is "t" a number"? no -> no match
I also don't understand it retrieves the "19" but does not retrieve "1".
Sorry if this is a stupid question, I'm really new at this
1 2 3 4 5 6 7 |
import re x = 'trash bag 19th of July 1.456 3x times 20 juice' y = re.findall( '[0-9]+[0-9]' ,x) print (y) |
I was doing some testing looking to understand regular expressions, I wrote the code and I thought it would not retrieve any numbers. When I run the code, why does it retrieve them? The way I wrote it, I thought that if a number is not followed by another number it wouldn't be retrieved.
Do I understand this correctly: "is 1 a number? yes. is 9 a number? yes. is "t" a number"? no -> no match
I also don't understand it retrieves the "19" but does not retrieve "1".
Sorry if this is a stupid question, I'm really new at this