Finding Acronyms Using Regex In Python -
i'm trying use regex in python match acronyms separated periods. have following code:
import re test_string = "u.s.a." pattern = r'([a-z]\.)+' print re.findall(pattern, test_string) the result of is:
['a.'] i'm confused why result. know + greedy, why first occurrences of [a-z]\. ignored?
the (...) in regex creates group. suggest changing to:
pattern = r'(?:[a-z]\.)+'
Comments
Post a Comment