Extract Acronyms Patterns From String Using Regex
I have this problem: list_= ['blabla S.P.A words J.R words. , words','words words !! words s.r.l words. D.T. words','words words I.B.M. words words.'] I would like to have: ['S.P.
Solution 1:
You just need to make the final period optional. Also lookbehind for a space or the start of the string before the first letter to ensure it's not part of another word, and lookahead after the end for a space or the end of the string:
pattern = r'(?i)(?:^|(?<= ))(?:[a-z]\.)+[a-z]\.?(?= |$)'
Post a Comment for "Extract Acronyms Patterns From String Using Regex"