Regular expression that matches a word followed by word(s) containing any character

A Regular expression that matches a word followed by word(s) containing any character is “[w](.*)”.


Java implementation of above is as follows:


public class TestPattern {
public static void main(String [] args){
String line = "public void isKeyword(String word){";
// matches a word followed by word(s) containing any character
if(line.matches("[w](.*)")){
System.out.println("Match found");
}
else {
System.out.println("Match not found");
}
}
}

Keep Coding !!!

Leave a Reply

Your email address will not be published. Required fields are marked *