i use lucene search but lucene has a bunch of special characters to escape like:
- && || ! ( ) { } [ ] ^ \" ~ * ? : \\
i am havin
Use regular expression to replace those characters in one go.
example:
String s="some text && || []!{} ()^*?~ and ";
Pattern p= Pattern.compile("([-&\\|!\\(\\){}\\[\\]\\^\"\\~\\*\\?:\\\\])");
s=p.matcher(s).replaceAll("\\\\$1");
System.out.println(s);\\prints some text \&\& \|\| \[\]\!\{\} \(\)\^\*\?\~ and