简体   繁体   中英

Extract data with regex from html

I would like to extract items from this sample html, more specificly, i would like to isolate the following ones: algp1, PRODUCTION 50733 GEN_APPL KANTOOR

<table width="95%" border="1">
<tr><td colspan=3><a name="algp1"></a><img src="menu/db2inst.jpg">  <font color="#FF0000" size="+1">algp1</font> (PRODUCTION, 50733)</td></tr>
<tr><td width="20%" valign=top><a name="GENAPPLP"></a><img src="menu/db2db.jpg"><font color="#00CC00"><b> GEN_APPL</font></b><br>(GENAPPLP)</td><td width="15%" valign=top>PARK</td><td width="70%" valign=top><font size="2">BOOKINGCARPARKING&sbquo; CUSTOMERS&sbquo; </font></td></tr>
<tr><td width="20%" valign=top></td><td width="15%" valign=top>RDC</td><td width="70%" valign=top><font size="2">DBREL_SCHEMA_RDCPROJECT&sbquo; DBVERSION&sbquo; </font></td></tr>
<tr><td width="20%" valign=top><a name="KANTOORP"></a><img src="menu/db2db.jpg"><font color="#00CC00"><b> KANTOOR</font></b><br>(KANTOORP)</td><td width="15%" valign=top>CDDB</td><td width="70%" valign=top><font size="2">BATIMENTS&sbquo; BATIMENTS_EXC&sbquo; OFFICES&sbquo; OFFICES_EXC&sbquo; RECETTES&sbquo; RECETTES_EXC&sbquo; </font></td></tr>
<tr><td width="20%" valign=top></td><td width="15%" valign=top>IDR</td><td width="70%" valign=top><font size="2">ADMINISTRATION&sbquo; ADMINISTRATION_EXC&sbquo; ARROND&sbquo; ARROND_EXC&sbquo; BUREAU&sbquo; BUREAU_EXC&sbquo; CODEX&sbquo; CODEX_EXC&sbquo; COMMUNE&sbquo; COMMUNE_EXC&sbquo; COMPETENCE&sbquo; COMPETENCE_EXC&sbquo; COMPTE&sbquo; COMPTE_EXC&sbquo; LNKBCC&sbquo; LNKBCC_EXC&sbquo; LNKBCI&sbquo; LNKBCI_EXC&sbquo; LNKBPC&sbquo; LNKBPC_EXC&sbquo; LNKBS&sbquo; LNKBS_EXC&sbquo; LNKCBRR&sbquo; LNKCBRR_EXC&sbquo; LNKCS&sbquo; LNKCS_EXC&sbquo; MAP_CP_BUREAU&sbquo; PAYS&sbquo; PAYS_EXC&sbquo; PROVINCE&sbquo; PROVINCE_EXC&sbquo; RANGE_RUE&sbquo; RANGE_RUE_EXC&sbquo; REGION&sbquo; REGION_EXC&sbquo; RUE&sbquo; RUE_EXC&sbquo; SERVICE&sbquo; SERVICE_EXC&sbquo; TPCODEX&sbquo; TPCODEX_EXC&sbquo; TPCOMPTE&sbquo; TPCOMPTE_EXC&sbquo; </font></td></tr>
<tr><td width="20%" valign=top></td><td width="15%" valign=top>RDC</td><td width="70%" valign=top><font size="2">DBREL_SCHEMA_RDCPROJECT&sbquo; DBVERSION&sbquo; </font></td></tr>
</table>

Check out JTidy . It will parse the HTML and give you a DOM interface to iterate over.

I would strongly recommend not using a regexp for all but the simplest cases. HTML isn't regular and has no end of edge cases to trip you up.

Take a look at regulazy...

It will allow you to create a regexp from an input string with a simple point and click interface.

http://osherove.com/tools/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM