Archive

Archive for August 23rd, 2007

java.util.regex.PatternSyntaxException: Dangling meta character ‘*’ near index 0

August 23rd, 2007 Arun Manivannan 11 comments

The same error comes when the regex is “+”

Here is the solution.

Enclose your * and + within square brackets.

Here is my code.

public static final String [] wildCards={"[*]","%","@","&","[+]"};

public static void main(String[] args) {
String s="!@#$%^&*()";
s=stripWild(s, wildCards);
System.out.println(s);
}