Search code examples
rubyregexregex-negationacronym

Regular expression to find unknown acronyms


I need a regular expression that will pick out lines with ALL CAPS or unknown acronyms.

ie: something like

/[A-Z]{2,}/ 

combined with

/(?!USA|UK|TLA)/

Solution

  • You mean something like this?

    \b(?!(?:USA|UK|TLA)\b)[A-Z]{2,}\b
    

    See it here on Rubular

    \b is a word boundary to ensure that it will find complete words.