【问题标题】:How to check for link regex in text with RSpec?如何使用 RSpec 检查文本中的链接正则表达式?
【发布时间】:2015-09-13 22:02:11
【问题描述】:

我有一个看起来像这样的 html 字符串:

Click the link below:
<a href="http://example.com/foo/bar?token=1HwyaHz2XX4sEEgqng9M">Verify</a>

我想检查链接是否存在,但用通配符代替我不关心的参数。我试过了,但它不匹配:

expect(html).to match %r{<a href="http://example.com/foo/bar?token=(.+)">Verify</a>}

我怎样才能让它工作?

【问题讨论】:

    标签: ruby regex rspec


    【解决方案1】:

    您需要转义可能被解释为正则表达式匹配器的特殊字符。这里?

    expect(html).to match %r{<a href="http://example.com/foo/bar\?token=(.+)">Verify</a>}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 2010-09-30
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多