How to match a line not containing a word in Java Regex

Java 8Object Oriented ProgrammingProgramming

Example

Live Demo

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NoRegTest {
   public static void main(String[] args) {
      String s="^fun";
      Pattern pattern = Pattern.compile(s);
      Matcher matcher = pattern.matcher("Java is fun");

      if(!matcher.find()) {
         System.out.println("not found");
      }
   }
}

Output

not found
raja
Published on 03-May-2018 06:54:56
Advertisements