java - 正则表达式匹配电子邮件主题中的 base64 编码

标签 java regex

我尝试将正则表达式与 java 匹配,但找不到正确的正则表达式

我想匹配 =?utf-8?B?XXXXXXXX=?=

=?utf-8?B?UmVtaW5kZXI=?=

我尝试过:

s.matches("=\\?utf\\-8\\?B\\?.*=\\?=");
s.matches("=\\?utf-8\\?B\\?.*=\\?=");

最佳答案

你确定吗?您使用的是哪个版本的 Java?

我已经对您的场景进行了基本测试,它有效......

public static void main(String[] args) {

    String input = "=?utf-8?B?UmVtaW5kZXI=?=";
    String input2 = "irege";

    String regex = "=\\?utf\\-8\\?B\\?.*=\\?=";

    System.out.println(input.matches(regex));
    System.out.println(input2.matches(regex));

}

控制台输出:

true
false

关于java - 正则表达式匹配电子邮件主题中的 base64 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9999501/

相关文章:

java - 如何正确重新启动 java.util.Timer?

javascript - 请有人帮我理解正则表达式的 exec 方法吗?

Python 正则表达式匹配段落

java - Eclipse 控制台中的 Windows-1250

java - ClassNotFoundException: com.sun.faces.config.ConfigureListener - 将 jar 部署到 Eclipse 下配置的 Tomcat

java - 边框不显示在我的图像中

c# - 搜索带有 xml 命名空间前缀 C# 的 XML 元素

html - 在 Ruby 中获取页面上所有 href 内容的最简单方法?

java - 字符串分词器 : split string by comma and ignore comma in double quotes

java - Java 7 Update 21 的新 WebStart 行为