问题描述
我想匹配正则表达式字符串,因为它将逐行从另一个文件读取。如果该字符串在字符串前后带有正斜杠(/),则不应与之匹配。
String text="defaults is Volvo";
String patternString = "Volvo";
//This so that it matches anything before and after the string
patternString = ".*" + patternString + ".*";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(text);
boolean matches = matcher.find();
它可以正常工作,但可以说我是text="home/Volvo/local"
,我不希望认为该文本是匹配的。因为它在文本前后包含正斜杠。 (*注意:正斜杠位于字符串的中间,而不是^开头或$的末尾)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)