Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this regex:</p> <pre><code>((?:\b[A-Z']+\b\s*)+) </code></pre> <p>Please note that you may need the apostrophe in the regex character class as it can occur inside the UPPERCASE word like it does in <code>ISN'T</code>.</p> <p>Java code:</p> <pre><code> String sourcestring = "Hello there I AM ALL UPPERCASE and NONE of me is LOWERCASE. True? ISN'T IT Not!"; Pattern re = Pattern.compile("((?:\\b[A-Z']+\\b\\s*)+)"); Matcher m = re.matcher(sourcestring); int mIdx = 0; while (m.find()){ for( int groupIdx = 0; groupIdx &lt; m.groupCount()+1; groupIdx++ ){ System.out.println( "[" + mIdx + "][" + groupIdx + "] = " + m.group(groupIdx)); } mIdx++; } </code></pre> <p>This matches:</p> <pre><code>I AM ALL UPPERCASE NONE LOWERCASE ISN'T IT </code></pre> <p>You can play with this at <a href="http://regex.powertoy.org/?pat=%28%28%3F%3A%5Cb%5BA-Z%27%5D+%5Cb%5Cs%2a%29+%29&amp;syn=javaSyntax&amp;anim=0&amp;rep=&amp;in=Hello%20there%20I%20AM%20ALL%20UPPERCASE%20and%20NONE%20of%20me%20is%20LOWERCASE.%20True%3F%20ISN%27T%20IT%20Not%21%0ADoes%20JOHN%27S%20TEXT%20ALSO%20appear%20AS%20LOWERCASE%20or%20is%20it%20MORE%20mixed.%0AThis%20is%20WORTH%20DESCRIBING%21%20Isn%27t%20IT%3F%0A" rel="nofollow">RegexPowertoy</a></p> <hr> <p><strong>Update:</strong> </p> <p>To match acronyms with periods like <code>U.S.</code> and avoid single letter acronyms <code>P.</code>, you can modify the regex to this:</p> <pre><code>((?:[A-Z]\.){2,}|(?:\b[A-Z][A-Z']*\b[?!]?\s*)+) </code></pre> <p>and play with it <a href="http://regex.powertoy.org/?pat=%28%28%3F%3A%5Cb%5BA-Z%27.%5D+%5Cb%5C.%3F%5Cs%2a%29+%29&amp;syn=javaSyntax&amp;anim=0&amp;rep=&amp;in=Hello%20there%20I%20AM%20ALL%20UPPERCASE%20and%20NONE%20of%20me%20is%20LOWERCASE.%20True%3F%20ISN%27T%20IT%20Not%21%0ADoes%20JOHN%27S%20TEXT%20ALSO%20appear%20AS%20LOWERCASE%20or%20is%20it%20MORE%20mixed.%0AThis%20is%20WORTH%20DESCRIBING%21%20Isn%27t%20IT%3F%20How%20about%20U.S.%20currency%3F%0A" rel="nofollow">here</a> and code can be checked <a href="http://www.myregextester.com/?r=4dbb517e" rel="nofollow">here</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload