请教一个关于JSP的问题 我要做一个JSP操作文本数据的页面但是没办法读取出来我想要的内容要读取的内容如下[内容开始]要读取的内容标题:要读取的内容[/内容结束]我希望能准确读取出来 “要读取的内容”请大家帮帮忙 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.util.regex.*;import java.util.ArrayList;public class RegexUse{ public static void main(String[] args){ String str="[aaa]123[/aaa]abcde[aaa]yuuiower[/aaa]fgh[aaaa]ssdfsdf[/aaa]ijk[/smfdsf]sdfksdf[a]nimdf[/a]"; String preStr1="\\[\\w+\\]"; String str1="\\w+"; String tailStr1="\\[/\\w+\\]"; Pattern pattern=Pattern.compile(preStr1+str1+tailStr1); Matcher matcher=pattern.matcher(str); ArrayList list=new ArrayList(); while(matcher.find()){ int start=matcher.start(); int end=matcher.end(); String strCurrent=str.substring(start,end); int firstLeft=strCurrent.indexOf(']'); int secondRight=strCurrent.indexOf('[',2); String[] tag=strCurrent.split("\\]"+str1+"\\[/"); if((tag[0]+"]").equals("["+tag[1])){ String result=strCurrent.substring(firstLeft+1,secondRight); list.add(result); } } System.out.println (list); }}嗯,你把这段代码改改吧,就肯定是你需要的.list里的东西肯定就是你要的. 谢谢wdaogang的回复 另:正则表达式我是实在不会。。所以做字符的时候很痛苦 用不用这个regex,用其它实现也可以.比如专用String里的几个函数,不过它们也得用到正则表达式里的东西.好好看些资料吧,正则表达式有时还是蛮好的,特别是对字符串操作. 如何获取JSTL解析后的流文件? 各位大侠们,在eclipse中怎么编写servlet?新手! Struts 異常問題??? 框架内页面跳转,RequestDispatcher.forward()没搞定,请高人指点一下! 什么是action? 三维数组的赋值问题,请高手帮忙 如何在jsp中读文件(应该比较常用吧) 请问,使用JSP的自定义标签,有什么好处和坏处? java如何把文本合成音频格式(MP3) 为什么要用动态sql 小弟想求一个struts的分页代码,很急,在线等 有点糊涂,请大家解释一下,谢谢!
import java.util.ArrayList;
public class RegexUse{
public static void main(String[] args){
String str="[aaa]123[/aaa]abcde[aaa]yuuiower[/aaa]fgh[aaaa]ssdfsdf[/aaa]ijk[/smfdsf]sdfksdf[a]nimdf[/a]";
String preStr1="\\[\\w+\\]";
String str1="\\w+";
String tailStr1="\\[/\\w+\\]";
Pattern pattern=Pattern.compile(preStr1+str1+tailStr1);
Matcher matcher=pattern.matcher(str);
ArrayList list=new ArrayList();
while(matcher.find()){
int start=matcher.start();
int end=matcher.end();
String strCurrent=str.substring(start,end);
int firstLeft=strCurrent.indexOf(']');
int secondRight=strCurrent.indexOf('[',2);
String[] tag=strCurrent.split("\\]"+str1+"\\[/");
if((tag[0]+"]").equals("["+tag[1])){
String result=strCurrent.substring(firstLeft+1,secondRight);
list.add(result);
}
} System.out.println (list);
}
}
嗯,你把这段代码改改吧,就肯定是你需要的.list里的东西肯定就是你要的.
wdaogang
的回复
另:
正则表达式我是实在不会。。
所以做字符的时候很痛苦