日期:2014-05-20 浏览次数:20668 次
String str1 = "address :is \"From\" \"dummy@dummyxyz.com\", address :is \"From\" \"emilychewpccw@gmail.com\""; String regEx = ".\"From\"\\s\""; //这个需要各位大虾帮忙修改的地方 Pattern pattern = Pattern.compile(regEx); Matcher mather = pattern.matcher(str1); boolean flag = mather.matches(); while (mather.find()) { // System.out.println( mather.group() ); } String[] strs = str1.split(regEx); for (String s : strs) { System.out.println(s); }
String str1 = "address :is \"From\" \"dummy@dummyxyz.com\", address :is \"From\" \"emilychewpccw@gmail.com\""; String regEx = "[\\w]*@[\\w]*.com"; //这个需要各位大虾帮忙修改的地方 Pattern pattern = Pattern.compile(regEx); Matcher mather = pattern.matcher(str1); boolean flag = mather.matches(); while (mather.find()) { System.out.println( mather.group() ); } // String[] strs = str1.split(regEx); // for (String s : strs) { // System.out.println(s); // }
------解决方案--------------------
用楼上的方法好些。如果按照楼主的思路来需要匹配的字符有
address :is \"From\" \"
\", address :is \"From\" \"
\"
很难匹配啊
------解决方案--------------------
重复造轮子不如网上搜搜来的快
------解决方案--------------------
String str1 = "address :is \"From\" \"dummy@dummyxyz.com\", address :is \"From\" \"emilychewpccw@gmail.com\"";
String regEx = "address :is \"From\""; //这个需要各位大虾帮忙修改的地方
Pattern pattern = Pattern.compile(regEx);
Matcher mather = pattern.matcher(str1);
boolean flag = mather.matches();
while (mather.find()) {
// System.out.println( mather.group() );
}
String[] strs = str1.split(regEx);
for (String s : strs) {
System.out.println(s);
}
------解决方案--------------------
在网上搜一下好了