加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Pattern正则

发布时间:2020-12-14 01:34:39 所属栏目:百科 来源:网络整理
导读:nginx的日志经常是用引号把字段抱起来,如下: ['UfaNode" "10.4.3.175" "10.4.1.51:31002" "[18/Sep/2014:13:00:01 +0800]" "0.110" "0.110" "-" "200" "Ok" "163" "102400" "xiaomi" "thumbnail" "-" "POST /ufa_new/downloadBlock HTTP/1.1" "Python-urll

nginx的日志经常是用引号把字段抱起来,如下:

['UfaNode" "10.4.3.175" "10.4.1.51:31002" "[18/Sep/2014:13:00:01 +0800]" "0.110" "0.110" "-" "200" "Ok" "163" "102400" "xiaomi" "thumbnail" "-" "POST /ufa_new/downloadBlock HTTP/1.1" "Python-urllib/2.6']

我们在解析的时候,就需要使用正则去解析:

Pattern pattern = Pattern.compile(""([^"]+)" "([^"]+)" "([^"]+)" "([^"]+)" "([^"]+)" "([^"]+)" "([^"]+)" "([^"]+)" "([^"]+)" "([^"]+)"" +
" "([^"]+)"");

Matcher matcher = pattern.matcher(text);
if(matcher.find()){

Stringstr=matcher.group(x);

}

----------------------------------------------------------------------------------

public static void main(String[] args) { // TODO Auto-generated method stub Pattern p = Pattern.compile(""(.*?)""); String s = new String(""aaa" "bbb" "ccc d,ee" ").trim(); System.out.println(s); Matcher m = p.matcher(s); while(m.find()){ System.out.println(m.group()); } System.out.println(m); }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读