Reputation: 2025
I am trying to write a regex in Java with Intellij IDE but .compile() is getting
cannot resolve symbol 'compile'
private boolean isUrlFormatValid(String url) {
Pattern pattern = new Pattern.compile("blabla");
//some other stuff
}
And I have imported these at the beginning of the class:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
.compile is not resolved. Do I need to add something else or you think something is wrong with intellij idea ?
Note: I have also tried by defining with full path like:
Pattern p = new java.util.regex.Pattern.compile("blabla");
But did not work as well.
Upvotes: 0
Views: 2806
Reputation: 585
Pattern.compile("blabla");
This is a static method on the Pattern
class (notice the capital P in Pattern
. A static method does not need an instance to run. So simply remove the new
keyword.
Upvotes: 2