我有简单的 html 代码:
<span class="someclass" title="4.5 stars"></span>
或者它可能是:
<span class="someclass" title="5 stars"></span>
我使用了 ((\d+\.\d+)|(\d+)) star 但它提取了 3 个组,我需要一个带有数值的组。
如何在一组中使用正则表达式提取两个字符串中的 4.5 和 5?
谢谢!
请您参考如下方法:
尝试删除内部括号:
(\d+\.\d+|\d+) star
此外,您可能希望首先考虑使用 HTML 解析器提取属性,而不是将正则表达式直接应用于原始 HTML。
