gpt4 book ai didi

复杂字符之间的 Java Regex 文本

转载 作者:行者123 更新时间:2023-11-30 09:27:37 24 4
gpt4 key购买 nike

我正在尝试借助正则表达式从字符串中提取文本,但我以前没怎么用过它,我无法弄清楚 Pattern.compile 的格式。

我想从以下字符串中减去重量(9 盎司):

<li><b>Shipping Weight:</b> 9 ounces (<a href="http://www.amazon.com/gp/help/seller/shipping.html?ie=UTF8&amp;asin=0982817509&amp;seller=ATVPDKIKX0DER">View shipping rates and policies</a>)</li>

print("Actual Weight:" + link.outerHtml());
Pattern p = Pattern.compile("Weight:\\</\\b\\>(.*?)\\ (");
Matcher m = p.matcher(link.outerHtml());
m.find();
System.out.println(m.group(1));

我的 Pattern.compile 格式应该是什么。我试图在“重量:”和“(”之间进行切换。

任何帮助都会很棒!我已经搜索了一段时间,但找不到解释格式的好地方。

最佳答案

你甚至不需要组。在这种情况下看后面的作品:

Pattern p = Pattern.compile("(?<=Weight:</b> )[^(]*");

关于复杂字符之间的 Java Regex 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14498353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com