Commit 535464a2 authored by 马博's avatar 马博

test

parent 43a6f0d8
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
package utils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by hanzhanli on 2017/8/16.
*/
public class StringUtil {
public static String generateStringByTime(){
Date date=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("MMdd");
return sdf.format(date)+"-"+(int)(Math.random()*100);
}
public static String generateRandomString(int length) {
String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random = new Random();
StringBuffer buf = new StringBuffer();
for (int i = 0; i < length; i++) {
int num = random.nextInt(36);
buf.append(str.charAt(num));
}
return buf.toString();
}
public static String getMatcher(String regex, String source,int index) {
String result = "";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(source);
if (matcher.find()) {
result = matcher.group(1);
}
return result;
}
public static void main(String[] args) {
String s = "{\"code\":\"0\",\"desc\":\"获取标签成功\",\"data\":{\"matchTagNums\":[\"20101\"],\"bannedTagNums\":[\"30101\"],\"promoteURLTagNums\":[\"40101\"],\"materialTagNums\":[\"50101\"]}}";
String source = "\"matchTagNums\":[\"(.*?)\"]";
System.out.println(getMatcher(source,s,1));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment