Last active
August 8, 2017 00:21
-
-
Save ozziexsh/cc7993405c299a0f32fdd4601cafc063 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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