package com.zcxk.core.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * @author Andy
 * @date 2021-07-22 11:03
 */
public class CommonUtils {

	/**
	 * 转义正则特殊字符 （$()*+.[]?\^{}
	 * \\需要第一个替换，否则replace方法替换时会有逻辑bug
	 */
	public static String makeQueryStringAllRegExp(String str) {
		if(StringUtils.isBlank(str)){
			return str;
		}
		return str.replace("\\", "\\\\").replace("*", "\\*")
				.replace("+", "\\+").replace("|", "\\|")
				.replace("{", "\\{").replace("}", "\\}")
				.replace("(", "\\(").replace(")", "\\)")
				.replace("^", "\\^").replace("$", "\\$")
				.replace("[", "\\[").replace("]", "\\]")
				.replace("?", "\\?").replace(",", "\\,")
				.replace(".", "\\.").replace("&", "\\&");
	}

}