字符串解析问题 test = "hello [135]!!!!!![134]表情处理[134444444444444]";如这样的字符串 我需要得到 []号的值 还需要得到 每一个[]的index值谢谢各位 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.util.regex.Matcher;import java.util.regex.Pattern;public class Test { public static void main(String[] args) { String str="hello [135]!!!!!![134]表情处理[134444444444444]"; Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])"); Matcher matcher = pattern.matcher(str); int i=0; while (matcher.find()) { System.out.println("index:"+(i++)+",Content:"+matcher.group()); } }} 知道了 String str = "hello [135]!!!!!![134]表情处理[134444444444444]"; Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])"); Matcher matcher = pattern.matcher(str); int i = 0; while (matcher.find()) { System.out.println(matcher.start()+" : "+matcher.end()); System.out .println("index:" + (i++) + ",Content:" + matcher.group() ); } String str="hello [135]!!!!!![134]表情处理[134444444444444]"; Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])"); Matcher matcher = pattern.matcher(str); int i=0; while (matcher.find()) { System.out.println("StartIndex:"+ (matcher.start()-1)); System.out.println( "EndIndex:"+(matcher.end()-1)); System.out.println("index:"+(i++)+",Content:"+matcher.group());}这样就可以获取到了,每一个“[]”StartIndex 是开始的索引,EndIndex是结束的索引 String str="hello [135]!!!!!![134]表情处理[134444444444444]"; Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])"); Matcher matcher = pattern.matcher(str); int i=0; while (matcher.find()) {System.out.println("StartIndex:"+ (matcher.start()-1));System.out.println( "EndIndex:"+(matcher.end()-1));System.out.println("index:"+(i++)+",Content:"+matcher.group());}这个是好的 String str="hello [135]!!!!!![134]表情处理[134444444444444]"; Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])"); Matcher matcher = pattern.matcher(str); int i=0; while (matcher.find()) {System.out.println("StartIndex:"+ (matcher.start()-1));System.out.println( "EndIndex:"+(matcher.end()-1));System.out.println("index:"+(i++)+",Content:"+matcher.group());} smpp短信网关 的问题 没分了 程序错在哪? 急!!!求助java语音聊天 与其他语言相比,JAVA除了跨平台,还有优点吗? 请高手帮我解决下finalize的用法问题,我对此不很了解!在此先谢谢了!! JSplitPane中Divider的定位问题 高难度问题,看看就有分送! 用Eclipse开发的一点困惑,求关于Tree SCJP要考Image吗? 請問applet中如何改變字體? 最近一直在做robot类 抓到的屏幕图像却没有鼠标的图像在 如何将java程序生成exe文件
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Test {
public static void main(String[] args) {
String str="hello [135]!!!!!![134]表情处理[134444444444444]";
Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])");
Matcher matcher = pattern.matcher(str);
int i=0;
while (matcher.find()) {
System.out.println("index:"+(i++)+",Content:"+matcher.group());
}
}
}
Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])");
Matcher matcher = pattern.matcher(str);
int i = 0;
while (matcher.find()) {
System.out.println(matcher.start()+" : "+matcher.end());
System.out
.println("index:" + (i++) + ",Content:" + matcher.group() );
}
Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])");
Matcher matcher = pattern.matcher(str);
int i=0;
while (matcher.find()) {
System.out.println("StartIndex:"+ (matcher.start()-1));
System.out.println( "EndIndex:"+(matcher.end()-1));
System.out.println("index:"+(i++)+",Content:"+matcher.group());
}
这样就可以获取到了,每一个“[]”StartIndex 是开始的索引,EndIndex是结束的索引
Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])");
Matcher matcher = pattern.matcher(str);
int i=0;
while (matcher.find()) {
System.out.println("StartIndex:"+ (matcher.start()-1));
System.out.println( "EndIndex:"+(matcher.end()-1));
System.out.println("index:"+(i++)+",Content:"+matcher.group());
}
这个是好的
Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])");
Matcher matcher = pattern.matcher(str);
int i=0;
while (matcher.find()) {
System.out.println("StartIndex:"+ (matcher.start()-1));
System.out.println( "EndIndex:"+(matcher.end()-1));
System.out.println("index:"+(i++)+",Content:"+matcher.group());
}