Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with RegEx for decimal numbers

Status
Not open for further replies.

skhoury

IS-IT--Management
Nov 28, 2003
386
0
0
US
Hello all...I've attempted to parse the following piece of HTML table for decimal numbers with limited luck. So far, i've gotten my RegEx to extract decimal numbers but I can't get it to recognize the value ".286792" below. Likewise, it is also capturing the "W. TF" because it has a "." in it.

Here is my expression so far...
\(?[0-9]{0,3}\.[0-9]{0,7}\)?

Any thoughts on what I am missing so far?

Thanks all,

Sam

<tr>
<td valign="top" align="left" bgcolor="#FFFFCC" class="ArticlePagesBodycopyReg" width="38%">W. TF</td> <td bgcolor="#FFFFCC" width="2%">&nbsp;</td>
<td valign="top" align="right" bgcolor="#FFFFCC" class="ArticlePagesBodycopyReg" width="18%">.286792</td> <td bgcolor="#FFFFCC" width="2%">&nbsp;</td>
<td valign="top" align="right" bgcolor="#FFFFCC" class="ArticlePagesBodycopyReg" width="13%">(0.022222)</td> <td bgcolor="#FFFFCC" width="2%">&nbsp;</td>
<td valign="top" align="center" bgcolor="#FFFFCC" class="ArticlePagesBodycopyReg" width="13%">0.16</td>
<td bgcolor="#FFFFCC" width="2%">&nbsp;</td>
<td valign="top" align="center" bgcolor="#FFFFCC" class="ArticlePagesBodycopyReg" width="10%">8.87</td>
</tr>
 
Your expression thinks capturing only a period is okay. You'll want to require numbers on one side or the other.

This will work:

Code:
\(?(?:\d{1,3}\.\d{0,7}|\d{0,3}\.\d{1,7})\)?
 
Perfect - it works. Thanks!

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top