java正则表达式

1.截取需要的数据,想截取的字符串并不想带上开头和结尾,举例来说(?=exp)代表匹配以exp结尾的字符串,但匹配出来的结果并不带exp,例如(?=ing)匹配reading,结果为read;(?<=exp)匹配以exp开头的字符串,但结果不带exp,例如(?<=read)匹配reading,结果为ing。
HttpResponse response = Unirest.get(url).asString();
Matcher matcher = Pattern.compile("(?<="data":\{".{1,10}"😃\{".{0,3}day":.?(?=,"qt)").matcher(response.getBody());
String js="";
while (matcher.find()){
js= matcher.group()+"}";
}
中间的 .
?代表任意多的字符但是尽可能的少匹配 .{1,10}代表这个位置最少有一个最多有十个任意的字符

posted @ 2022-07-24 21:23  Xiaobaishushu  阅读(28)  评论(0)    收藏  举报