^(123\.js|321\.java)$
例2:反选匹配除了123.js,正早321.java这两个特定的文件外的所有文判清瞎件掘空。
^(?!123\.js$)(?!321\.java$).*$
例3:匹配所有.js文件。
^.*\.js$
/*** @author eatonfang
* @version 1.0
*
*/
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// System.out.println()
String str1 = "D:/PjlWorkspace/monitor/ts/app-shangdu.xml"
String str2 = "app-shangdu.xml"
String regex = "[^(/|\森铅\|\\\\|//)]+\\.[^(/|\此兄好\|\\\\|//)]+"
System.out.println(str2.matches(regex))
System.out.println(str1.replaceAll(regex, "name"))
}
}
运行结果:
true
D:/PjlWorkspace/monitor/ts/name
如果路径分隔符只有/一种可能的话,就可以这样写: [^/]+\\.[^/]+
我是考虑到路径尘余分隔符还可以写成\, \\, //, 这几种可能,所以才写成那样子的
package baiduTest2import java.io.FileOutputStream
import java.util.Iterator
import java.util.LinkedHashMap
import java.util.Map
import org.apache.poi.hssf.usermodel.HSSFCell
import org.apache.poi.hssf.usermodel.HSSFRow
import org.apache.poi.hssf.usermodel.HSSFSheet
import org.apache.poi.hssf.usermodel.HSSFWorkbook
import net.sf.json.JSONArray
import 州运net.sf.json.JSONObject
public class JSONProcess {
public JSONArray getJsonObject(String str){
JSONArray jo=JSONArray.fromObject(str)
return jo
}
public void 册腊梁writeExcel(JSONArray ja) throws Exception{
Map map=new LinkedHashMap()
map.put("id", "id")
map.put("tag1", "tag1")
map.put("tag2", "tag2")
map.put("tag3", "tag3")
map.put("tag4", "tag4")
map.put("tag5", "tag5")
map.put("tag6", "tag6")
map.put("tag7", "tag7")
map.put("tag8", "tag8")
HSSFWorkbook workbook = new HSSFWorkbook()
// 生成一个表格并设置表格默认列宽度为25个字节
HSSFSheet sheet = workbook.createSheet("sheet1")
sheet.setDefaultColumnWidth((short) 25)
// 生成表格标题
HSSFRow titleRow = sheet.createRow(0)
int columnLength1 = 20
HSSFCell[] title = new HSSFCell[columnLength1]
for (int i = 0 i < columnLength1 i++) {
title[i] = titleRow.createCell((short) i)
title[i].setEncoding(HSSFCell.ENCODING_UTF_16)
title[i].setCellValue("")
}
// 生成表格表头行
HSSFRow headerRow1 = 局庆sheet.createRow(0)
HSSFCell[] header1 = new HSSFCell[columnLength1]
Iterator it=map.keySet().iterator()
int count=0
while(it.hasNext()) {
header1[count] = headerRow1.createCell((short) count)
header1[count].setEncoding(HSSFCell.ENCODING_UTF_16)
header1[count].setCellValue(map.get(it.next()).toString())
count++
}
// 遍历集合数据,产生数据行
FileOutputStream out = new FileOutputStream("E:/excelTest.xls")
int cellNum = 0
if (ja != null) {
for (int rownum = 0 rownum < ja.size() rownum++) {
HSSFRow row = sheet.createRow(rownum + 1)
JSONObject json = (JSONObject) ja.getJSONObject(rownum)
HSSFCell[] cell = new HSSFCell[columnLength1]
int counter=1
cell[0] = row.createCell((short) 0)
cell[0].setEncoding(HSSFCell.ENCODING_UTF_16)
cell[0].setCellValue(json.get("id").toString())
JSONArray ja1 = (JSONArray) json.getJSONArray("tags")
for(int j=0j<ja1.size()j++){
JSONObject json1=(JSONObject)ja1.get(j)
Iterator it1=json1.entrySet().iterator()
String key=it1.next().toString()
cell[counter] = row.createCell((short) counter)
cell[counter].setEncoding(HSSFCell.ENCODING_UTF_16)
cell[counter].setCellValue(key.split("=")[1])
counter++
}
}
}
workbook.write(out)
out.close()
}
public static void main(String[] args) {
JSONProcess jsonProcess=new JSONProcess()
String str="[{\"id\":1237869662,\"tags\":[{\"201201310009409169\":\"沙海\",\"weight\":\"123\"},{\"211007220000015286\":\"惊叹号\",\"weight\":\"117\"},{\"201110220006272797\":\"漫工厂\",\"weight\":\"5\"},{\"201102070003148762\":\"超好看\",\"weight\":\"28\"},{\"520\":\"出版人\",\"weight\":\"858\"},{\"2328\":\"作家\",\"weight\":\"5632\"},{\"4029\":\"盗墓笔记\",\"weight\":\"57495\"},{\"16115\":\"南派三叔\",\"weight\":\"754\"}]},{\"id\":2899165812,\"tags\":[{\"34735\":\"学生一族\",\"weight\":\"124648\"},{\"12544\":\"热爱生活\",\"weight\":\"130120\"},{\"285\":\"音乐\",\"weight\":\"5374344\"},{\"983\":\"水瓶\",\"weight\":\"69854\"},{\"464\":\"美食\",\"weight\":\"19040573\"}]}]"
JSONArray ja=jsonProcess.getJsonObject(str)
try {
jsonProcess.writeExcel(ja)
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace()
}
}
}
那是要我写了,我是有多闲啊。
其实这是json结构的字符串啊。在java里面很好处理啊,有现成的类处理这种字符串的。
放到txt或者excel也不难啊。但是代码量挺多的。
你需要的jar包。
commons-beanutils.jar
commons-collections.jar
commons-httpclient.jar
commons-lang.jar
commons-logging.jar
ezmorph-1.0.3.jar
json-lib-2.3-jdk15.jar
poi-2.5.1.jar
因为百度只能上传一个附件,其他jar包你自己弄吧。在百度搜索就行。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)