java - Want to extract values from text file using regex -


"00.00.00.00" 00.00.00.00 - - [07/jun/2016:00:00:00 -0700] "hey /acd?bg=1 http/1.1" 200 2 "-" "00.00.00.00:0000" "java/1.8.0_66" - - 2000  

there records above, want extract values fields , each field separated space , please help

i using below:

string p;     pattern pattern = pattern.compile(p);     matcher matcher = pattern.matcher(str);     if (matcher.find()){     system.out.println(matcher.group(1));     } 

but not getting correct output. new regex desired out put is

00.00.00.00 00.00.00.00 - - 07/jun/2016:00:00:01 -0700 hey /acd?bg=1 http/1.1 200  

i've got pattern want, isn't pretty:

^"((?:\d\d?\d?\.){3}\d\d?\d?)" ((?:\d\d?\d?\.){3}\d\d?\d?) (-) (-) (\[\d\d\/\w+\/\d{4}(?::\d\d){3} -\d{4}\]) "(.*?)" (\d{3}) 

to break down bit (because it's nasty):

^ makes start @ beginning of string.

((?:\d\d?\d?\.){3}\d\d?\d?) match , capture first ip address, each element being composed of between 1 , 3 digits. same pattern used match second ip address well.

(-) capture hyphens - not sure why want it, it's in desired input.

(\[\d\d\/\w+\/\d{4}(?::\d\d){3} -\d{4}\]) captures timestamp (the bit in square brackets).

"(.*?)" match , capture text string.

finally, (\d{3}) capture http status code.

taken together, pattern match stuff want string provided.


Comments