这是Java中的这样一个字符串。
String string="abc$[A]$def$[B]$ghi";
我想搜索位于$[*]$
模式的单词。字符串上方的结果为A
,B
。
答案 0 :(得分:5)
String s = "abc$[A]$def$[B]$ghi";
Pattern p = Pattern.compile("\\$\\[.*?\\]\\$");
Matcher m = p.matcher(s);
while(m.find()){
String b = m.group();
System.out.println(">> " +b.substring(2, b.length()-2));
}
答案 1 :(得分:0)
使用正则表达式。在Java中,您可以使用Pattern class。
答案 2 :(得分:0)
您可以使用正则表达式。查看课程Pattern和Matcher。
在这种情况下,您将使用的正则表达式为:
\$\[.*?\]\$
或者,您可以使用String.indexOf和String.substr。