thufir

target sscce

Sep 17th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. package regex;
  2.  
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.         String s = "/t fred";
  10.         lastWord(s);
  11.     }
  12.  
  13.     //(\w+)\.
  14.     private static void lastWord(String sentence) {
  15.         System.out.println("\n\ntrying\n" + sentence + "\nmatches:");
  16.         Pattern pattern = Pattern.compile("(\\w+)");
  17.         Matcher matcher = pattern.matcher(sentence);
  18.         String match = null;
  19.         int i = 1;
  20.         while (matcher.find()) {
  21.             match = matcher.group(i);
  22.             System.out.println(match);
  23.             i++;
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment