我使用 lucene 搜索,但 lucene 有一堆特殊字符可以转义,例如:
i use lucene search but lucene has a bunch of special characters to escape like:
- && || ! ( ) { } [ ] ^ " ~ * ? :
我在转义这些字符时遇到问题,因为它们太多了,如果我使用 String.replaceAll() 方法,我最终会得到很长的代码行来转义字符.最好的方法是什么?谢谢!
i am having problem escaping these characters because they are too many and if i use the String.replaceAll() method, i'll just end up having a really long line of code just for escaping the characters. what is the best way to do? thanks!
还有一个方法叫QueryParser#escape,这可能有用:
There is also a method called QueryParser#escape, which may be useful:
返回一个字符串,其中 QueryParser 期望被转义的那些字符被前面的 转义.
Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding .
这篇关于如何以一种方法转义java中的一组特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何检测 32 位 int 上的整数溢出?How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
return 语句之前的局部变量,这有关系吗?Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
如何将整数转换为整数?How to convert Integer to int?(如何将整数转换为整数?)
如何在给定范围内创建一个随机打乱数字的 intHow do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
java的行为不一致==Inconsistent behavior on java#39;s ==(java的行为不一致==)
为什么 Java 能够将 0xff000000 存储为 int?Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)