title: Regular Expressions on Punctuation
body: <p>So I'm completely new to <em>regular expressions</em>, and I'm trying to use Java's <code>java.util.regex</code> to find punctuation in input strings. I won't know what kind of punctuation I might get ahead of time, except that (1) !, ?, ., ... are all valid puncutation, and (2) "&lt;" and ">" mean something special, and don't count as punctuation.
  The program itself builds phrases pseudo-randomly, and I want to strip off the punctuation at the end of a sentence before it goes through the random process.</p>
  
  <p>I can match entire words with any punctuation, but the matcher just gives me indexes for that word. In other words:</p>
  
  <pre><code>Pattern p = Pattern.compile("(.*\\!)*?");
  Matcher m = p.matcher([some input string]);
  </code></pre>
  
  <p>will grab any words with a <code>"!"</code> on the end. For example:</p>
  
  <pre><code>String inputString = "It is a warm Summer day!";
  Pattern p = Pattern.compile("(.*\\!)*?");
  Matcher m = p.matcher(inputString);
  String match = inputString.substring(m.start(), m.end());
  </code></pre>
  
  <p>results in --> String match ~ "day!"</p>
  
  <p>But I want to have <code>Matcher</code> index just the <code>"!"</code>, so I can just split it off.</p>
  
  <p>I could probably make cases, and use <code>String.substring(...)</code> for each kind of punctuation I might get, but I'm hoping there's some mistake in my use of regular expressions to do this.</p>