title: How do you extract only the uppercase portions of a string in Stata?
body: <p>Here's a sample of the data:</p>
  
  <pre><code>part1
  "Cambridge, Maryland TEST MODEL SEADROME"
  "L.B. MAYER HONORED"
  "A TOWN MOVES"
  "U.S. SAVINGS BONDS RALLY"
  "N.D. NOSES OUT S.M.U. BY 27 TO 20"
  "Philadelphia, Pa. BURN 2,300 SQUEALERS"
  "Odd Bits In To-day's News"
  "Saratoga Springs, N.Y. DIAVOLO IS STAR AT BRILLIANT SPA OPENING"
  "Risk Death in Daring Race"
  "Philadelphia, PA. IT'S HIGHER EDUCATION"
  "806 DECORATIONS"
  "Snow Hauled 20 Miles For Skiers"
  "F.D.R. ASKS VICTORY EFFORT"
  </code></pre>
  
  <p>Each string either has an upper and lowercase portion, or is all uppercase. I've been trying to use regular expressions to extract only the uppercase portions of the string, but haven't had any luck. The best I've been able to do is identify when a string starts or ends with a certain number of uppercase characters:</p>
  
  <pre><code>generate title = regexs(0) if regexm(part1, "^[A-Z][A-Z][A-Z].*[A-Z][A-Z][A-Z]$")
  </code></pre>
  
  <p>I've also tried the following, which I pulled from another question in the forum:</p>
  
  <pre><code>generate title = regexs(0) if(regexm(part1, "\b[A-Z]{2,}\b"))
  </code></pre>
  
  <p>Which is supposed to look for words with at least two uppercase letters in a row, but it only returns missing values for me. I'm using Stata version 13.1 for Mac.</p>