java.util.regex.PatternSyntaxException: Dangling meta character ‘*’ near index 0
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);
}





No use
Worked like a charm !!! Thx !!
Thanks
Thanx, you have saved me hours :>
Worked for mee….. Thanks!
thanx, it worked for me. I was having issue with “?”, it get solved after using “[?]“.
Thanks! It worked perfecly with split()
String[] temp = stringVar.split(“[+]“);
*bow*
thanks, it helped me with my Strint.split() problem
Thanks .. this was helpful
getSomeString().replaceAll(“*”, “.*”) wont work either, with the same error message. use getSomeString().replaceAll(“[*]“, “.*”) instead.
Greetings, thanks for the advice!
Thanks it was helpful to me. can you explain why it is giving error by without enclosing “*” with brackets