import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^([0-9.]+)\\s(.)\\s(.)\\s\\[(.*)\\s(\\+[0-9]*)\\]\\s\\\"GET|POST\\\"";
final String string = "127.0.0.1 - - [11/Sep/2015:08:15:33 +0600] \"GET / HTTP/1.1\" 200 4189\n"
+ "127.0.0.1 - - [11/Sep/2015:08:15:33 +0600] \"GET /icons/blank.gif HTTP/1.1\" 200 148\n"
+ "127.0.0.1 - - [11/Sep/2015:08:15:33 +0600] \"GET /icons/folder.gif HTTP/1.1\" 200 225\n"
+ "127.0.0.1 - - [11/Sep/2015:08:15:33 +0600] \"GET /icons/text.gif HTTP/1.1\" 200 229\n"
+ "127.0.0.1 - - [11/Sep/2015:08:15:33 +0600] \"GET /icons/unknown.gif HTTP/1.1\" 200 245\n"
+ "127.0.0.1 - - [11/Sep/2015:08:15:33 +0600] \"GET /favicon.ico HTTP/1.1\" 404 1207\n"
+ "127.0.0.1 - - [11/Sep/2015:08:15:40 +0600] \"GET /public/ HTTP/1.1\" 200 1023\n"
+ "127.0.0.1 - - [11/Sep/2015:08:15:37 +0600] \"GET /public/ HTTP/1.1\" 200 1023\n"
+ "127.0.0.1 - - [08/Dec/2015:11:22:28 +0600] \"GET /public/index.php HTTP/1.1\" 200 1023\n"
+ "127.0.0.1 - - [08/Dec/2015:11:22:31 +0600] \"GET /favicon.ico HTTP/1.1\" 404 1239\n"
+ "127.0.0.1 - - [08/Dec/2015:11:22:34 +0600] \"GET / HTTP/1.1\" 200 4189\n"
+ "127.0.0.1 - - [08/Dec/2015:11:22:34 +0600] \"GET /icons/blank.gif HTTP/1.1\" 200 148\n"
+ "127.0.0.1 - - [08/Dec/2015:11:22:34 +0600] \"GET /icons/folder.gif HTTP/1.1\" 200 225\n"
+ "127.0.0.1 - - [08/Dec/2015:11:22:34 +0600] \"GET /icons/unknown.gif HTTP/1.1\" 200 245\n"
+ "127.0.0.1 - - [08/Dec/2015:11:22:34 +0600] \"GET /icons/text.gif HTTP/1.1\" 200 229\n"
+ "127.0.0.1 - - [08/Dec/2015:11:22:52 +0600] \"GET / HTTP/1.1\" 200 1023\n"
+ "127.0.0.1 - - [08/Dec/2015:11:23:05 +0600] \"GET / HTTP/1.1\" 200 1023\n"
+ "127.0.0.1 - - [08/Dec/2015:11:23:07 +0600] \"GET /public/index.php HTTP/1.1\" 404 16638\n"
+ "127.0.0.1 - - [08/Dec/2015:11:23:12 +0600] \"GET / HTTP/1.1\" 200 1023\n"
+ "127.0.0.1 - - [08/Dec/2015:11:23:40 +0600] \"GET /auth/ HTTP/1.1\" 301 332\n"
+ "127.0.0.1 - - [08/Dec/2015:11:23:40 +0600] \"GET /auth HTTP/1.1\" 404 16638\n"
+ "127.0.0.1 - - [08/Dec/2015:11:23:45 +0600] \"GET /auth/login HTTP/1.1\" 404 16638\n"
+ "127.0.0.1 - - [08/Dec/2015:11:23:49 +0600] \"GET / HTTP/1.1\" 200 1023\n"
+ "127.0.0.1 - - [08/Dec/2015:11:44:02 +0600] \"GET / HTTP/1.1\" 200 1046\n"
+ "127.0.0.1 - - [08/Dec/2015:12:11:53 +0600] \"GET / HTTP/1.1\" 200 1023\n"
+ "127.0.0.1 - - [29/Dec/2015:10:29:46 +0600] \"GET / HTTP/1.1\" 200 11160\n"
+ "127.0.0.1 - - [29/Dec/2015:10:29:47 +0600] \"GET /_debugbar/assets/stylesheets?1451362463 HTTP/1.1\" 200 196851\n"
+ "127.0.0.1 - - [29/Dec/2015:10:29:47 +0600] \"GET /_debugbar/assets/javascript?1451362459 HTTP/1.1\" 200 348784\n"
+ "127.0.0.1 - - [29/Dec/2015:10:29:48 +0600] \"GET /favicon.ico HTTP/1.1\" 200 -\n"
+ "127.0.0.1 - - [29/Dec/2015:10:30:58 +0600] \"GET /auth HTTP/1.1\" 404 29966\n"
+ "127.0.0.1 - - [29/Dec/2015:10:32:24 +0600] \"GET /_debugbar/open?max=20&offset=0 HTTP/1.1\" 200 289\n"
+ "127.0.0.1 - - [29/Dec/2015:11:08:46 +0600] \"GET /auth/register HTTP/1.1\" 404 28750\n"
+ "127.0.0.1 - - [30/Dec/2015:08:43:01 +0600] \"GET /auth/register HTTP/1.1\" 404 27092\n"
+ "127.0.0.1 - - [30/Dec/2015:08:43:14 +0600] \"GET /_debugbar/assets/stylesheets?1451362463 HTTP/1.1\" 200 196851\n"
+ "127.0.0.1 - - [30/Dec/2015:08:43:14 +0600] \"GET /_debugbar/assets/javascript?1451362459 HTTP/1.1\" 200 348784\n"
+ "127.0.0.1 - - [30/Dec/2015:08:43:15 +0600] \"GET /favicon.ico HTTP/1.1\" 200 -\n"
+ "127.0.0.1 - - [30/Dec/2015:11:51:32 +0600] \"GET / HTTP/1.1\" 200 9902\n"
+ "127.0.0.1 - - [30/Dec/2015:11:51:34 +0600] \"GET /favicon.ico HTTP/1.1\" 200 -\n"
+ "127.0.0.1 - - [30/Dec/2015:12:22:13 +0600] \"GET /auth HTTP/1.1\" 404 28622\n"
+ "127.0.0.1 - - [28/Mar/2016:12:32:18 +0600] \"GET / HTTP/1.1\" 200 9881\n"
+ "127.0.0.1 - - [28/Mar/2016:12:32:38 +0600] \"GET /_debugbar/assets/stylesheets?1451362463 HTTP/1.1\" 200 196851\n"
+ "127.0.0.1 - - [28/Mar/2016:12:32:38 +0600] \"GET /_debugbar/assets/javascript?1451362459 HTTP/1.1\" 200 348784\n"
+ "127.0.0.1 - - [28/Mar/2016:12:32:39 +0600] \"GET /favicon.ico HTTP/1.1\" 200 -\n";
final String subst = "";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html