【问题标题】:Remove a part of string that is not fix删除未修复的字符串部分
【发布时间】:2023-02-09 02:19:40
【问题描述】:

我有一个像这样的字符串:

String balise1 = "<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=Windows-1252 other balises ... ">";
String balise2 = "<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=UTF-8 other balises ... ">";
String balise3 = "<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=ISO 8859-1 other balises ... ">";

我想删除不是的字符集部分

我如何使用 replace、ReplaceAll 或 Regex 执行此操作

问候

我尝试用 Regex 替换所有但没有成功

【问题讨论】:

  • edit 并提供有效的 java,您应该在字符串周围加上引号。还分享你尝试的代码
  • 这个“3D”的东西是什么?不应该在那里
  • 我尝试用 Regex 替换所有但没有成功请分享您的尝试并解释什么不起作用以及原因。

标签: java regex string


【解决方案1】:

使用以下regex;s+charset=S+

List<String> values = List.of(
        "<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=Windows-1252 other balises ... ">",
        "<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=UTF-8 other balises ... ">",
        "<meta http-equiv=3D"Content-Type" content=3D"text / html; charset=ISO8859-1 other balises ...">"
);

for (String s : values) {
    System.out.println(s);
    s = s.replaceAll(";\s+charset=\S+", "");
    System.out.println(s);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-26
    • 2017-03-01
    • 1970-01-01
    • 2017-07-02
    • 2020-11-16
    • 2014-07-24
    • 1970-01-01
    相关资源
    最近更新 更多