I need to build a regular expression for all nonempty sequences of letters other than : file, for,from.
So I should end up getting all the values from my text input excluding the above 3 words.
Is this a correct way to represent it?
^(?:(?!file|for|from).)*$
Also I was trying to use this regex pattern in my java program and assumed it should work. But it does not.
My sample code is as follows:
Pattern p = Pattern.compile("^(?:(?!file|for|from).)*$");
// Split input with the pattern
String[] result =
p.split("file is not there from for this time for this test");
for (int i=0; i<result.length; i++)
System.out.println(result[i]);
Is there an error in my regex or is there some error with the way I am using regex in java?
Please advise.
Thank you.
You should do something like this: