title: regex to get numerator and denominator for a ratio x/y
body: <p>The output is fine, I'm assuming the input is "nice" and of the form x/y, with no spaces, and is only integer values:</p>
  
  <pre><code>run:
  272/273
  matching group 1
  272
  273
  matching group 2
  BUILD SUCCESSFUL (total time: 0 seconds)
  </code></pre>
  
  <p>code: </p>
  
  <pre><code>package stackoverflow;
  
  import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  import static java.lang.System.out;
  
  public class Ratio {
  
      private static String line = "272/273";
  
      public static void main(String[] args) {
          out.println(line);
          ratios(1);
          ratios(2);
      }
  
      private static void ratios(int numeratorDenominator) {
          out.println("matching group " + numeratorDenominator);
          Pattern pattern = Pattern.compile("(\\w+)");
          Matcher matcher;
          matcher = pattern.matcher(line);
          while (matcher.find()) {
              try {
                  out.println(matcher.group(numeratorDenominator));
              } catch (IndexOutOfBoundsException obe) {
              }
          }
      }
  }
  </code></pre>
  
  <p>However, it's not quite up to par.  Is there a different, or better, way to get the denominator?  I'm not looking for some obscure regex, but, for instance, to anchor to the end of the line, get the last word instead of first?</p>
  
  <p>For my purposes, word works fine, although digits would also work.  /d I think.</p>