获取不带连字符的文本 - Capybara

Get text without hyphen - Capybara

我有一个 table 行元素

<th scope="row" class="u-printHyphensManual row">
            Advan­&shy;taged
</th>

如何获取没有连字符的文本?即 elem.text returns "Advantaged" 而不是 "Advan-taged".

我正在使用水豚

find('th').text 更改为 find('th').text.gsub(/[^A-za-z]/,'')

这适用于这种情况,但根据您真正要解决的一般问题,这可能会产生意想不到的后果。

您可以通过输入代码并使用 string.encode 将 Unicode 字符放入字符串中,也可以将代码直接放入正则表达式中。软连字符的 Unicode 是 \u00AD

text.gsub('\u00AD'.encode('utf-8'), '')

text.gsub(/\u00AD/, '')

如果这不起作用,请尝试替换文字 &shy;

text.gsub('&shy;', '')