java - How to use regular expressions to add delimiters? -


hi have sample log file here:

jan 1 22:54:17 drop   %logsource% >eth1 rule: 7; rule_uid: {c1336766-9489-4049-9817-50584d83a245}; jan 1 22:54:22 drop   %logsource% >eth1 rule: 7; rule_uid: {c1336766-9489-4049-9817-50584d83a245}; jan 1 22:54:23 drop   %logsource% >eth1 rule: 7; rule_uid: {c1336766-9489-4049-9817-50584d83a245}; jan 1 22:54:41 drop   %logsource% >eth1 rule: 7; rule_uid: {c1336766-9489-4049-9817-50584d83a245}; 

the default delimiter semi-colon(;) , want separate timestamp , "drop", "drop" "%logsource%" delimiter. didnt expected result. whole code insert delimiter.) main idea add log file arraylist string(which can use regular expressions according current knowledge of java) , add delimiters accordingly.

the error shown below:

exception in thread "main" java.lang.runtimeexception: uncompilable source code - erroneous tree type: @ testing.testing.main(testing.java:31) starts line liststring.replaceall("regex command")

note: tried putting delimiter between timestamp , "drop" , error occured. don't understand how use regular expressions , need on it!

public class testing {  public static void main(string[] args) throws filenotfoundexception {      scanner infile1 = new scanner(new file("filename")).usedelimiter(";");     list<string> temps = new arraylist<string>();     string liststring = "";     while (infile1.hasnext()) {         // find next line         string token1 = infile1.next();         temps.add(token1);     }     infile1.close();     (string s : temps) {         liststring += s + "\t";         liststring.replaceall(s,([a-za-z]{3}\s\d{1,2}\s\d{2}:\d{2}:\d{2})(\s)(drop)));     }      system.out.println(liststring);  } 

"[a-za-z]{3}\\s\\d{1,2}\\s\\d{2}:\\d{2}:\\d{2}\\sdrop" 

the above should work. don't need parenthesis. reason particular exception since number of left , right parenthesis in original expression don't match


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -