I have a simple regex which searches a sentence to see if it contains the word of|for|in|at and here is my regex that is almost working in regexpal:
[^A-Za-z]of|for|in|at[^A-Za-z]
I run it on following setences:
show me the weather of seattle
show me the weather in seattle
show me the weather for seattle
show me the weather at seattle
and here are results:

When I use it in my Java code it doesnt works at all. In regexpal too is shows space with for and at which I defined at start and end. Can someone please tell what is wrong with my regex and how to search for one of many words in a sentence
I always get else condition in my java which means it is not matching regex. Here is my java code:
public class Regex
{
public static void main(String[] args)
{
String str = "show me the weather in seattle";
if(str.matches("[^A-Za-z]of|for|in|at[^A-Za-z]")){
System.out.println("Yayyy!!");
}
else{
System.out.println("OMG now what to do");
}
}
}
matcheschecks the string is completely. It is not looking for a match. try add.*at start and end regexp[^A-Za-z](of|for|in|at)[^A-Za-z]or, better,\\W(of|for|in|at)\\W