fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. String regex = ".*plecam.*";
  7. String str = "Noi am fost la mare apoi plecam la munte!";
  8. Pattern pattern = Pattern.compile(regex);
  9. Matcher matcher = pattern.matcher(str);
  10. boolean matchFound = matcher.matches();
  11. // System.out.println("--> " + matcher.matches() + "\n");
  12. if(matchFound) {
  13. System.out.println("Match found " + matchFound);
  14. } else {
  15. System.out.println("Match not found "+ matchFound);
  16. }
  17. }
  18. }
  19.  
Success #stdin #stdout 0.11s 55968KB
stdin
Standard input is empty
stdout
Match found true