Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

regexp and multiple matches
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



Report this thread to moderator Post Follow-up to this message
Old Post
Garry Horoupian
04-26-05 01:58 AM


Re: regexp and multiple matches
"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.

Report this thread to moderator Post Follow-up to this message
Old Post
SM Ryan
04-26-05 01:58 AM


Re: regexp and multiple matches
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


Report this thread to moderator Post Follow-up to this message
Old Post
davidhbigelow@simplifiedlogic.com
04-26-05 01:58 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Tcl archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:33 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.