I have to check a string for a specific word. Condition is that: it starts and ends with either space or underscore or it is start or end of string. Case is insensitive.
Following is my code:
package example;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
String test = "The starting of week";
String t = "[^_ ]the[ _$]";
Pattern p = Pattern.compile(t,Pattern.CASE_INSENSITIVE);
Matcher matcher = p.matcher(test);
if( matcher.find() ){
System.out.println(true);
}
}
}
What am I doing wrong?