All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mogudiandian.util.regex.RegexUtils Maven / Gradle / Ivy

There is a newer version: 1.0.19
Show newest version
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("|", "\\|");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy