Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package regex;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Main {
- public static void main(String[] args) {
- String s = "/t fred";
- lastWord(s);
- }
- //(\w+)\.
- private static void lastWord(String sentence) {
- System.out.println("\n\ntrying\n" + sentence + "\nmatches:");
- Pattern pattern = Pattern.compile("(\\w+)");
- Matcher matcher = pattern.matcher(sentence);
- String match = null;
- int i = 1;
- while (matcher.find()) {
- match = matcher.group(i);
- System.out.println(match);
- i++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment