Java regex to exclude a specific String constant


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);
   }
}

Updated on: 24-Jun-2020

907 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements