gpt4 book ai didi

java - 在 assertEquals() 中使用正则表达式不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:12:45 24 4
gpt4 key购买 nike

我在 assertEquals() 语句中使用正则表达式时遇到问题。这是声明。

Assert.assertEquals("regexp:*TST-*[0-9]{5}", driver.getTitle());

但是我得到这个错误:

org.junit.ComparisonFailure: expected:<[regexp:*TST-*[0-9]{5}]> but was:<[[#TST-23570] This is the new summary]>

看起来正则表达式只是一个正在被比较的字符串。我错过了什么?

最佳答案

看起来您实际上并没有使用正则表达式。看起来这可能就是您想要做的?

Assert.assertTrue(driver.getTitle().matches("*TST-*[0-9]{5}"));

编辑#1:

看起来你的正则表达式可能不太正确,试试:

Assert.assertTrue(driver.getTitle().matches(".*TST-\\d{5}.*"));

关于java - 在 assertEquals() 中使用正则表达式不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4330360/

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