fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.lang.*;
  4. import java.util.*;
  5. import java.util.regex.Pattern;
  6. import java.util.stream.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. String strings[] = { "CardTIN is 1111", "Card-TIN:2222", "CardTINis3333", "Card@TIN@4444", "CardTIN@5555", "TINis9999", "test", "Card Tin is 1111" };
  14. String[] wordsList = {"TIN","tin"};
  15. String alt = "(?:" + String.join("|", wordsList) + ")";
  16. String regex = "(?i)^(?![a-zA-Z0-9]*" + alt + "[a-zA-Z0-9]*$).*" + alt + ".*";
  17. List<String> result = Arrays.stream(strings)
  18. .filter(word -> word.matches(regex))
  19. .collect(Collectors.toList());
  20.  
  21. for (String res : result)
  22. System.out.println(res);
  23. }
  24. }
Success #stdin #stdout 0.16s 54012KB
stdin
Standard input is empty
stdout
CardTIN is 1111
Card-TIN:2222
Card@TIN@4444
CardTIN@5555
Card Tin is 1111