Java Regular Expression to match a line that doesn't contain a word.


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);
   }
   returns true, if word does not match character kk
}

Updated on: 24-Jun-2020

393 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements