【发布时间】:2017-06-11 13:12:04
【问题描述】:
我想测试一下输出是否是这样的:
String s1 = "You have 5 Dollar in your bank account."
要通过测试,字符串需要相等,所以我需要一个相等的字符串:
String s2 = "You have (.*) Dollar in your bank account."
s1.equals(s2) 应该是真的。
(.*)不起作用,有没有简单的方法来实现这个?
【问题讨论】:
-
用正则表达式怎么样?
-
一个好的第一步是the docs -
equals没有提到正则表达式,matches确实提到了正则表达式。或谷歌“Java 中的正则表达式”。 -
谢谢,matches() 正是我要找的东西。