fork download
  1. x <- c("City of Fake Municipal Court", "City of Pretend Water Utility","City of Not Real Police Department","Fraud Hill Utility","El Imagined 344th District Court")
  2. regex <- "(?i)\\s*\\b(util(?:it(?:y|ies))?|MUNICIPAL|Police|Water|[0-9]+(?:st|[rn]d|th)?)(?:,?\\s)?"
  3. trimws(sub(regex, ", TX ", x, perl=TRUE))
Success #stdin #stdout 0.28s 39352KB
stdin
Standard input is empty
stdout
[1] "City of Fake, TX Court"          "City of Pretend, TX Utility"    
[3] "City of Not Real, TX Department" "Fraud Hill, TX"                 
[5] "El Imagined, TX District Court"