Archive

Archive for August 23rd, 2007

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

August 23rd, 2007 Arun Manivannan 8 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);
}

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis