-2

date = 2011-07-08 time = 10:55:06 timezone = "IST" device_name = "CR1000i" device_id = C010600504-TYGJD3 deploy_mode = "Route" log_id = 031006209001 log_type = "Anti Virus" log_component = "FTP" log_subtype = "Clean" status = "Denied" priority = Critical fw_rule_id = "" user_name = "hemant" virus = "codevirus" FTP_URL = "ftp.myftp.com" FTP_direction = "download" filename = "hemantresume.doc" file_size = "550k "file_path =" deepti / Shortcut toviral.lnk "ftpcommand =" RETR "src_ip = 10.103.6.100 dst_ip = 10.103.6.66 protocol =" TCP "src_port = 2458 dst_port = 21 dstdomain =" myftp.cpm "sent_bytes = 162 recv_bytes = 45 message="サーバーftp.myftpからのサイズ550kのファイルresume.docのFTPダウンロード。ファイルがウイルスコードウイルスに感染しているため、comを完了できませんでした。」

次に、上記の文字列を分割して、以下のようにキーと値のペアに基づいて出力を取得します。

array[0]=date=2011-07-08

array[1]=time=10:55:06

array[2]=timezone="IST"

array[3]=device_name='CR1000i"

.......

.......

助けてください..ありがとう

4

3 に答える 3

2

@Hlopikが提案するような(ほぼ)正規表現を使用してから、ループしてすべての一致を見つけることができます。

String text = "dstdomain=\"myftp.cpm\" sent_bytes=162 recv_bytes=45 message=\"An FTP download of File resume.doc of size 550k from server ftp.myftp.com could not be completed as file was infected with virus codevirus\"";
String patternText = "\\w+=([^ \"]+|\"[^\"]*\")";
Matcher matcher = Pattern.compile(patternText).matcher(text);
List<String> matches = new ArrayList<String>();
while (matcher.find()) {
    matches.add(matcher.group());
}

Array何らかの理由で結果が本当に必要な場合は、を使用できますmatches.toArray()

于 2012-06-27T13:23:07.000 に答える
1

インスピレーションを得るために、この正規表現を検討してください。これは、\w*=(["][^"]*["]|[^ ]*) 任意の数の単語(\ w)文字、等号、および引用符内のすべてのもの、または最初のスペースに一致するものに一致します。これは例に一致しますが、この正規表現には確かに何かがあります。単純すぎるでしょう:)

于 2012-06-27T12:58:19.920 に答える
1

以下のコードを見つけてください。コードはJAVAであることに注意してください。

StringBuilder testt = new StringBuilder("date=2011-07-08 time=10:55:06 timezone=\"IST\" device_name=\"CR1000i\" device_id=C010600504-TYGJD3 deployment_mode=\"Route\" log_id=031006209001 log_type=\"Anti Virus\" log_component=\"FTP\" log_subtype=\"Clean\" status=\"Denied\" priority=Critical fw_rule_id=\"\" user_name=\"hemant\" virus=\"codevirus\" FTP_URL=\"ftp.myftp.com\" FTP_direction=\"download\" filename=\"hemantresume.doc\" file_size=\"550k\" file_path=\"deepti/Shortcut to virus.lnk\" ftpcommand=\"RETR\" src_ip=10.103.6.100 dst_ip=10.103.6.66 protocol=\"TCP\" src_port=2458 dst_port=21 dstdomain=\"myftp.cpm\" sent_bytes=162 recv_bytes=45 message=\"An FTP download of File resume.doc of size 550k from server ftp.myftp.com could not be completed as file was infected with virus codevirus\"");

Pattern varPattern = Pattern.compile("[A-Z_]+=", Pattern.CASE_INSENSITIVE);

Matcher varMatcher = varPattern.matcher(testt);

List<String> list = new ArrayList<String>();

int startIndex = 0, endIndex=0;

boolean found=false;

while (varMatcher.find()) {

 endIndex = varMatcher.start();

 list.add(testt.substring(startIndex, endIndex));

 startIndex= varMatcher.start();

 found=true;

}

if(found){
 list.add(testt.substring(startIndex));
}

for(String s:list){
 System.out.println(s);
}
于 2012-06-28T06:10:17.140 に答える