当前位置:编程学习 > JAVA >>

跪求string中截取特定信息的方法

跪求string中截取特定信息的方法,最好有代码可以学习下谢谢各位大神了~

string 从txt文件中读取一条字符串

截取其中的特定的内容

写入mysql或者.xls

例如:alert tcp $HOME_NET 3505 -> $EXTERNAL_NET any (msg:"BACKDOOR autospy runtime detection - show nude pic"; flow:from_server,established; flowbits:isset,AutoSpy_ShowNudePicture; content:"nude Raider pic"; depth:15; metadata:policy security-ips drop; reference:url,www.spywareguide.com/product_show.php?id=1438; reference:url,www3.ca.com/securityadvisor/pest/pest.aspx?id=59685; classtype:trojan-activity; sid:6082; rev:2;)

中截取content:""的内容<nude Raider pic>写入.xls或者mysql里 --------------------编程问答-------------------- String a = 要截取的字符串.substring(截取的第一个字符的位数-1,要截取的最后一个字符的位数); --------------------编程问答-------------------- lz可以参照一下这个:

String str = "username=张三#userid=200100#userpasswd=123456";
String[] arr = str.split("#");
System.out.println(arr[0]);


运行结果:username=张三 --------------------编程问答--------------------
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ExactString {
public static void main(String[] args){
String input="alert tcp $HOME_NET 3505 -> $EXTERNAL_NET any (msg:\"BACKDOOR autospy runtime detection - show nude pic\"; flow:from_server,established; flowbits:isset,AutoSpy_ShowNudePicture; content:\"nude Raider pic\"; depth:15; metadata:policy security-ips drop; reference:url,www.spywareguide.com/product_show.php?id=1438; reference:url,www3.ca.com/securityadvisor/pest/pest.aspx?id=59685; classtype:trojan-activity; sid:6082; rev:2;)";
String regex="content:\"([^\"]*)";
Matcher m=Pattern.compile(regex).matcher(input);
while(m.find())
System.out.println(m.group(1));
}
}

正则表达式 --------------------编程问答-------------------- 对的 用正则表达式进行分检
补充:Java ,  Eclipse
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,