how can i escape a group of special characters in java in one method?(如何以一种方法转义java中的一组特殊字符?)
问题描述
我使用 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中的一组特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何以一种方法转义java中的一组特殊字符?
基础教程推荐
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
