有一段字符串是:
dsad<td class=\"yfnc_tabledata1\"><small>Zions Bancorporation</small></td>dsa<td class=\"yfnc_tabledata1\"><small>wangking</small></td>
我怎么能够在这段字符串里获得Zions Bancorporation,wangking这俩字符串?正则怎么写呢?
dsad<td class=\"yfnc_tabledata1\"><small>Zions Bancorporation</small></td>dsa<td class=\"yfnc_tabledata1\"><small>wangking</small></td>
我怎么能够在这段字符串里获得Zions Bancorporation,wangking这俩字符串?正则怎么写呢?
import java.util.regex.Pattern;/**
* @author wangking E-mail:[email protected]
* @version 创建时间:2009-9-16 下午01:02:38
* 类说明
*/
public class TestA { public static void main(String[] args) { Pattern pattern = Pattern.compile("<td class=\"yfnc_tabledata1\"><small>([a-zA-Z]+)(</small></td>)$");
Matcher matcher = pattern.matcher("dsad<td class=\"yfnc_tabledata1\"><small>Zions Bancorporation</small></td>dsa<td class=\"yfnc_tabledata1\"><small>wangking</small></td>");
if(matcher.find()){
System.out.println(matcher.group(1));
}
}
}
public static void main(String[] s){
Pattern p = Pattern.compile("<small>([a-zA-Z ]+)</small>");
String str = "dsad <td class=\"yfnc_tabledata1\"> <small>Zions Bancorporation </small> " +
"</td>dsa <td class=\"yfnc_tabledata1\"> <small>wangking </small> </td>";
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group(1));
}
}Zions Bancorporation
wangking
public static void main(String[] args) {
String str = "dsad <td class=\"yfnc_tabledata1\"> <small>Zions Bancorporation </small> </td>dsa <td class=\"yfnc_tabledata1\"> <small>wangking </small> </td>";
Pattern ptn = Pattern.compile("<small>([^<>]+)</small>");
Matcher mt = ptn.matcher(str);
while (mt.find()) {
String text = mt.group(1).trim();
System.out.println("found [" + text + "]");
}
}
}
import java.util.regex.*;public class Test1 {
public static void main(String[] args) {
String str = "dsad <td class=\"yfnc_tabledata1\"> <small>Zions Bancorporation </small> </td>dsa <td class=\"yfnc_tabledata1\"> <small>wangking </small> </td>";
Pattern ptn = Pattern.compile("<small>([^<>]+)</small>");
Matcher mt = ptn.matcher(str);
while (mt.find()) {
String text = mt.group(1).trim();
System.out.println("found [" + text + "]");
}
}
}
大虾帮我看看,我想抓取Zions Bancorporation, ZIMMER HOLDINGS INCimport java.io.*;
import java.net.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class GetIp{ public static void main(String args[]) throws MalformedURLException,IOException {
getContent("http://finance.yahoo.com/q/cp?s=^GSPC&alpha=Z");
}
public static void getContent(String URLSTR) {
try {
URL url = new URL(URLSTR);
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String line = null;
Pattern namePat = Pattern.compile("<small>([a-zA-Z ]+)</small>"); while ((line = br.readLine()) != null) {
// System.out.println(line);
Matcher m = namePat.matcher(line);
if (m.find()) {
System.out.println(m.group(1));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}