Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get all matching indices or values from a regexp

4 views
Skip to first unread message

Laurent

unread,
May 16, 2011, 8:55:50 PM5/16/11
to
Hi,

I want to parse some data, looking for a specific pattern. There can
be multiple matches on a line and I can never know ahead of time how
many there will be. What is the best way to get them all? Is it by
something like this:

while {[regexp -indices $pattern $data indices]} {
set found [string range $data [lindex $indices 0] [lindex $indices
1]
set data [string range [lindex $indices 1] end]
}

or is there a better way?

L

Aric Bills

unread,
May 16, 2011, 11:25:45 PM5/16/11
to

How about [regexp -inline -all $pattern $data] or [regexp -inline -all
-indices $pattern $data]?

0 new messages