Code Comments
Programming Forum and web based access to our favorite programming groups.Hello, I was wondering if anyone could tell me how to capture multiple matches of a regexp expression into a list. For example, if I wanted to parse an html row for it's cell values, regardless of how many cells there are: <tr><td>Timer values</td><td>1</td><td>2</td><td>3</td>........</tr> Thanks in advance
Post Follow-up to this message"Garry Horoupian" <ghoroupi@cisco.com> wrote:
# Hello,
#
# I was wondering if anyone could tell me how to capture multiple matches of
a
# regexp expression into a list.
#
# For example, if I wanted to parse an html row for it's cell values,
# regardless of how many cells there are:
#
# <tr><td>Timer values</td><td>1</td><td>2</td><td>3</td>........</tr>
tclsh <<':eof'
set string {<tr><td>Timer values</td><td>1</td><td>2</td><td>3</td>........<
/tr>}
puts [regexp -inline -all {<td>.*?</td>} $string]
:eof
{<td>Timer values</td>} <td>1</td> <td>2</td> <td>3</td>
tclsh <<':eof'
set string {<tr><td>Timer values</td><td>1</td><td>2</td><td>3</td>........<
/tr>}
puts [regexp -inline -all {<td>(.*?)</td>} $string]
:eof
{<td>Timer values</td>} {Timer values} <td>1</td> 1 <td>2</td> 2 <td>3</td>
3
tclsh <<':eof'
set string {<tr><td>Timer values</td><td>1</td><td>2</td><td>3</td>........<
/tr>}
set L {}
foreach {- cell} [regexp -inline -all {<td>(.*?)</td>} $string] {lappend L $
cell}
puts $L
:eof
{Timer values} 1 2 3
Note also that HTML is a type 2 language and cannot be properly parsed with
just a
regular expression. For example, if a table is nested within a <td>.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
You hate people.
But I love gatherings. Isn't it ironic.
Post Follow-up to this message
Garry Horoupian wrote:
> Hello,
>
> I was wondering if anyone could tell me how to capture multiple
matches of a
> regexp expression into a list.
>
> For example, if I wanted to parse an html row for it's cell values,
> regardless of how many cells there are:
>
> <tr><td>Timer values</td><td>1</td><td>2</td><td>3</td>........</tr>
>
>
>
> Thanks in advance
if memory serves:
regexp -all -inline {<td>[A-Za-z0-9\ ]+</td>} $data
Might get you close...
Dave
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.