com.mogudiandian.util.regex.RegexUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of joshua-util Show documentation
Show all versions of joshua-util Show documentation
Joshua's user-friendly utilities
package com.mogudiandian.util.regex;
/**
* 正则工具类
* @author Joshua Sun
* @since 1.0.0
*/
public final class RegexUtils {
private RegexUtils() {}
/**
* 对文本中的正则符号进行转义
* @param text 文本
* @return 转义后的文本
*/
public static String escape(String text) {
return text.replace("\\", "\\\\")
.replace("*", "\\*")
.replace("+", "\\+")
.replace("{", "\\{")
.replace("}", "\\}")
.replace("(", "\\(")
.replace(")", "\\)")
.replace("^", "\\^")
.replace("$", "\\$")
.replace("[", "\\[")
.replace("]", "\\]")
.replace("?", "\\?")
.replace(",", "\\,")
.replace(".", "\\.")
.replace("&", "\\&")
.replace("|", "\\|");
}
}