import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
/**
* 判断字符串是否在base64编码范围内
*/
public class MatchBase64 {
public static final String UTF8_BOM = "\uFEFF";
public static void main(String[] args) {
String plaintext = "5rih5a6JSOeahOWNmuWuou+8muS6uumXtOS4jeWAvOW+lwpodHRwczovL2Jsb2cuY3Nkbi5uZXQvRF9DX0hhbw==";
//删除BOM字符
if (plaintext.startsWith(UTF8_BOM)) {
plaintext = plaintext.substring(1);
}
if ( StringUtils.isEmpty(plaintext) ){
System.out.println("False:Is empty");
return;
}
String regex = "[A-Za-z0-9,/,=,+]+";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(plaintext);
if ( ! m.matches()) {
System.out.println("False:Don't match");
return;
}
System.out.println("True:matching");
}
}