Java regex to exclude a specific String constant

Java Programming Object Oriented ProgrammingJava8

regex ^((?!kk).)*$ returns true if a line does not contain kk, otherwise returns false

Example

public class RegTest {
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      String s="tutorials";
      boolean i=s.matches("^((?!kk).)*$");
      System.out.println(i);
   }
}
raja
Published on 22-Jun-2018 12:03:15
Advertisements