Akin Hwan
Akin Hwan

Reputation: 627

Python Regex for numbers and not string containing numbers (see example)

I would like to match number strings like '76' but not '76er'

I've tried the following, and experimenting with [^a-z] so I don't capture a-z characters after the 2-3 digits but for some reason not working with my test string

test = "Boston Celtics 112 Philadelphia 76ers 95"

should return ["112", "95"]

re.findall(r"\d{2,3}", mystring)

Upvotes: 0

Views: 95

Answers (1)

Alex Hall
Alex Hall

Reputation: 36013

Try r"\b\d{2,3}\b". \b means word boundary.

Upvotes: 2

Related Questions