473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Regular expression issue

I'm trying to parse a line of html as follows:

<td style="width:20%" align="left">101.120:( KPA (-)</td>
<td style="width:35%" align="left">Snow on Ground)0 </td>

however, sometimes it looks like this:

<td style="width:20%" align="left">N/A</td>
<td style="width:35%" align="left">Snow on Ground)0 </td>
I want to get either the numerical value 101.120 (which could be a
different number depending on the data that's been fed into the page,
or in terms of the second option, 'N/A'.

The regexp I'm using is:

..*?Pressure.*?"left">(?P<baro>\d+?|N/A)</td>|\sKPA.*?Snow\son\sGround

Can someone help me debug this. It's not picking up the number, and
I'm not sure I've got the syntax for '|' right, but can't find a
detailed tutorial on how to use |.

Any help would be appreciated.

Thanks

Matt

Jul 19 '06 #1
2 992
In <11**********************@m79g2000cwm.googlegroups .com>, dmbkiwi wrote:
I'm trying to parse a line of html as follows:

<td style="width:20%" align="left">101.120:( KPA (-)</td>
<td style="width:35%" align="left">Snow on Ground)0 </td>

however, sometimes it looks like this:

<td style="width:20%" align="left">N/A</td>
<td style="width:35%" align="left">Snow on Ground)0 </td>
I want to get either the numerical value 101.120 (which could be a
different number depending on the data that's been fed into the page,
or in terms of the second option, 'N/A'.

The regexp I'm using is:

.*?Pressure.*?"left">(?P<baro>\d+?|N/A)</td>|\sKPA.*?Snow\son\sGround

Can someone help me debug this. It's not picking up the number, and
I'm not sure I've got the syntax for '|' right, but can't find a
detailed tutorial on how to use |.
What about something like

align="left">((?P<baro>[\d.]+):\(\sKPA)|(?P<na>N/A).*Ground\)

You need the flags re.MULTILINE and re.DOTALL when compiling the regular
expression.

You'll have to check the 'baro' and 'na' groups to decide if it matched a
numerical value or 'N/A'.

Ciao,
Marc 'BlackJack' Rintsch
Jul 19 '06 #2
dm*****@gmail.com schrieb:
I'm trying to parse a line of html as follows:

<td style="width:20%" align="left">101.120:( KPA (-)</td>
<td style="width:35%" align="left">Snow on Ground)0 </td>

however, sometimes it looks like this:

<td style="width:20%" align="left">N/A</td>
<td style="width:35%" align="left">Snow on Ground)0 </td>
I want to get either the numerical value 101.120 (which could be a
different number depending on the data that's been fed into the page,
or in terms of the second option, 'N/A'.

The regexp I'm using is:

.*?Pressure.*?"left">(?P<baro>\d+?|N/A)</td>|\sKPA.*?Snow\son\sGround
Wouldn't it be simpler to use HTMLParser or something similar first to
separate text and HTML tags and get the content of each cell separately?
Then you have only to find the 'right' cell, possibly quite simply by
its position in the HTML table, and check if it contains 'N/A' or
something numeric (that check wouldn't need a regular expression if its
really so simple).

No Python here so I can't try it out to be more specific, but look for
HTMLParser in the library reference.

--
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
e-mail : Si*************@Bibliothek.Uni-Augsburg.DE
Jul 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
9
by: Pete Davis | last post by:
I'm using regular expressions to extract some data and some links from some web pages. I download the page and then I want to get a list of certain links. For building regular expressions, I use...
6
by: deepak_kamath_n | last post by:
Hello, I am relatively new to the world of regex and require some help in forming a regular expression to achieve the following: I have an input stream similar to: Slot: slot1 Description:...
12
by: =?Utf-8?B?SlA=?= | last post by:
I am a newbie to regular expressions and want to extract a number from the end of a string. The string would have these formats: image/4567 image/45678 image/456789 I would also want to...
18
by: Lit | last post by:
Hi, I am looking for a Regular expression for a password for my RegExp ValidationControl Requirements are, At least 8 characters long. At least one digit At least one upper case character
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.