Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Regex to match a scientific format string

Last post 08-28-2008, 9:27 AM by tezarin. 4 replies.
Sort Posts: Previous Next
  •  08-26-2008, 2:19 PM 45662

    Regex to match a scientific format string

    Hi all,

    I need a regex that matches a string like this: 8.120000e+01

    I have a HTML table, one of the fields title is "Element Value" and the values for this field will need to be in scientific notation format...

    I am using OpenNMS to collect data and am using this HTML page as a data page. The information I would like to be collected is the value of the field called Element Value. This value is in scientific notation format. I need to write a match statement in OpenNMS (using regex) which this match statement will do a search inside that HTML page and matches the value...

    Here's my HTML page and a sample "match" statement regex. Help me modify the regex so it works with my format. Thank you!

    HTML data page:

     

    <html>

    <head>

    <title>New page</title>

    </head>

    <body>

    <br>

    <table border="1" width="435">

    <tr>

    <td width="90">Element Name</td>

    <td width="111">Element Var</td>

    <td width="114">Element Value Tag</td>

    <td width="92">Element Value</td>

    </tr>

    <tr>

    <td width="90">testing_1</td>

    <td width="111">test-0/test1</td>

    <td width="114">value</td>

    <td width="92">9.420000e+01</td>

    </tr>

    <tr>

    <td width="90">testing_2</td>

    <td width="111">ctest-0/test2</td>

    <td width="114">value</td>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    </head>

    <body>

    <br>

    <table border="1" width="435">

    <tr>

    <td width="90">Element Name</td>

    <td width="111">Element Var</td>

    <td width="114">Element Value Tag</td>

    <td width="92">Element Value</td>

    </tr>

    <tr>

    <td width="90">testing_1</td>

    <td width="111">test-0/test1</td>

    <td width="114">value</td>

    <td width="92">9.420000e+01</td>

    </tr>

    <tr>

    <td width="90">testing_2</td>

    <td width="111">ctest-0/test2</td>

    <td width="114">value</td>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    <tr>

    <td width="90">Element Name</td>

    <td width="111">Element Var</td>

    <td width="114">Element Value Tag</td>

    <td width="92">Element Value</td>

    </tr>

    <tr>

    <td width="90">testing_1</td>

    <td width="111">test-0/test1</td>

    <td width="114">value</td>

    <td width="92">9.420000e+01</td>

    </tr>

    <tr>

    <td width="90">testing_2</td>

    <td width="111">ctest-0/test2</td>

    <td width="114">value</td>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    <td width="111">Element Var</td>

    <td width="114">Element Value Tag</td>

    <td width="92">Element Value</td>

    </tr>

    <tr>

    <td width="90">testing_1</td>

    <td width="111">test-0/test1</td>

    <td width="114">value</td>

    <td width="92">9.420000e+01</td>

    </tr>

    <tr>

    <td width="90">testing_2</td>

    <td width="111">ctest-0/test2</td>

    <td width="114">value</td>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    <td width="114">Element Value Tag</td>

    <td width="92">Element Value</td>

    </tr>

    <tr>

    <td width="90">testing_1</td>

    <td width="111">test-0/test1</td>

    <td width="114">value</td>

    <td width="92">9.420000e+01</td>

    </tr>

    <tr>

    <td width="90">testing_2</td>

    <td width="111">ctest-0/test2</td>

    <td width="114">value</td>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    <td width="92">Element Value</td>

    </tr>

    <tr>

    <td width="90">testing_1</td>

    <td width="111">test-0/test1</td>

    <td width="114">value</td>

    <td width="92">9.420000e+01</td>

    </tr>

    <tr>

    <td width="90">testing_2</td>

    <td width="111">ctest-0/test2</td>

    <td width="114">value</td>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    </tr>

    <tr>

    <td width="90">testing_1</td>

    <td width="111">test-0/test1</td>

    <td width="114">value</td>

    <td width="92">9.420000e+01</td>

    </tr>

    <tr>

    <td width="90">testing_2</td>

    <td width="111">ctest-0/test2</td>

    <td width="114">value</td>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    <td width="111">test-0/test1</td>

    <td width="114">value</td>

    <td width="92">9.420000e+01</td>

    </tr>

    <tr>

    <td width="90">testing_2</td>

    <td width="111">ctest-0/test2</td>

    <td width="114">value</td>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    <td width="114">value</td>

    <td width="92">9.420000e+01</td>

    </tr>

    <tr>

    <td width="90">testing_2</td>

    <td width="111">ctest-0/test2</td>

    <td width="114">value</td>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    <td width="92">9.420000e+01</td>

    </tr>

    <tr>

    <td width="90">testing_2</td>

    <td width="111">ctest-0/test2</td>

    <td width="114">value</td>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    </tr>

    <tr>

    <td width="90">testing_2</td>

    <td width="111">ctest-0/test2</td>

    <td width="114">value</td>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    <td width="111">ctest-0/test2</td>

    <td width="114">value</td>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    <td width="114">value</td>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    <td width="92">1.900000e+00</td>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    </tr>

    <tr>

    <td width="90">testing_3</td>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    <td width="111">test-0/test3</td>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    <td width="114">value</td>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    <td width="92">2.100000e+00</td>

    </tr>

    </table>

    </body>

    </html>

    </tr>

    </table>

    </body>

    </html>

    This is the match I need to be configured:

    matches="(?s).*Element\sValue\n>([0-9\... response-range="100-399"

     

    Thanks in advance!

     

     

  •  08-26-2008, 3:39 PM 45665 in reply to 45662

    Re: Regex to match a scientific format string

    <td width="92">((?:(?!Element Value)[^<])*)</td>

    Capture group 1 is your target.

    or:

    (?<=<td width="92">)(?:(?!Element Value)[^<])*(?=</td>)

    Capture group 0 is your target.


  •  08-27-2008, 10:19 AM 45694 in reply to 45665

    Re: Regex to match a scientific format string

    ddrudik,

     Thanks for your reply. It worked perfect :)

    Now, I have another question for you. I have another html page which I paste a part of it here. In this new page, I would like the regex to collect only the three numbers. I was able to write a regex, would that be possible for you to see if this is the correct regex? Thanks in advance :)

    This is the new HTML page:

    <table border="1">
    <tr>
    <td>CPU_Idle</td>
    <td>cpu-0/cpu-idle</td>
    <td>value</td>
    <td>92.300000</td>
    </tr>
    <tr>
    <td>CPU_System</td>
    <td>cpu-0/cpu-system</td>
    <td>value</td>
    <td>3.300000</td>
    </tr>
    <tr>
    <td>CPU_User</td>
    <td>cpu-0/cpu-user</td>
    <td>value</td>
    <td>11.600000</td>
    </tr>
    </table>

     

    And this is the regex:

    (?s).*?td>([0-9]+).([0-9]+).*\s+ 

     

  •  08-27-2008, 10:26 AM 45695 in reply to 45694

    Re: Regex to match a scientific format string

    Does OpenNMS support lookbehind? (?<=)

    If so, this would seem to work

    (?<=<td>)[0-9.-]+

    where the match itself (capture group 0) is your target.

    If not:

    <td>([0-9.-]+)

    where capture group 1 is your target.


  •  08-28-2008, 9:27 AM 45737 in reply to 45695

    Re: Regex to match a scientific format string

    Thanks again, you've been really helpful :)

    Actually, I tried the first one and it didn't work,...this is the one I came up with:  (?s).*?td>(([0-9]+).([0-9]+)).*\s+

    It's really nice of you to help.

    Bests :)
    Tezarin

     

View as RSS news feed in XML