how can i escape a group of special characters in java in one method?

前端 未结 4 1707
清酒与你
清酒与你 2021-01-11 19:56

i use lucene search but lucene has a bunch of special characters to escape like:

- && || ! ( ) { } [ ] ^ \" ~ * ? : \\

i am havin

4条回答
  •  清歌不尽
    2021-01-11 20:32

    There is also a method called QueryParser#escape, which may be useful:

    Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding \.

提交回复
热议问题