比如说字符串"Txt" 现在要求"xt"不匹配 只有"Txt"才匹配 大家给个通用的 谢谢
^.+Txt.+$
".+.Txt" 或 "^\S+.Txt$" 都可以
可以这样解决,比如你的字符串是str如下:
String str = "fgfsg.Txt";
Pattern pattern = Pattern.compile("Txt$");
Matcher matcher = pattern.matcher(str);
String txt = null;
while(matcher.find()){
txt = matcher.group();
System.out.println(txt);
}
这样就找到了
^.+Txt.+$这个应该可以吧。
你这是匹配文件名么,还是什么?
能给出具体的用例场景么?