Skip to content

Instantly share code, notes, and snippets.

@ozziexsh
Last active August 8, 2017 00:21
Show Gist options
  • Save ozziexsh/cc7993405c299a0f32fdd4601cafc063 to your computer and use it in GitHub Desktop.
Save ozziexsh/cc7993405c299a0f32fdd4601cafc063 to your computer and use it in GitHub Desktop.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.*;
public class Madlib {
public static void main(String a[]){
String stream = "My name is NAME and I work at COMPANY";
Pattern pattern = Pattern.compile("\\b[A-Z]{2,}\\b");
// Pattern pattern = Pattern.compile("\\{([A-Za-z0-9]+)\\}"); // use this to replace {word} instead of CAPITALS
Matcher matcher = pattern.matcher(stream);
List<String> words = new ArrayList<String>();
while(matcher.find()){
words.add(matcher.group());
}
System.out.println(words);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment