Mind.random()

random ramblings of an eccentric programmer

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); }

Comments