fork(1) download
  1. import java.util.*;
  2. import java.util.stream.*;
  3. import java.util.regex.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.*;
  7.  
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String paragraph = "I ate an apple, but I am still hungry, so I will eat pie";
  13. List<String> wordList = Arrays.asList("apple","hungry","pie");
  14. Pattern p = Pattern.compile("\\b(?:" + String.join("|", wordList) + ")\\b");
  15. Matcher m = p.matcher(paragraph);
  16. if (m.find()) {
  17. System.out.println("Found " + m.group());
  18. }
  19.  
  20. }
  21. }
Success #stdin #stdout 0.08s 27668KB
stdin
Standard input is empty
stdout
Found apple