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

getting all matches with [regexp -all]

78 views
Skip to first unread message

Khaled

unread,
Mar 28, 2005, 3:40:25 AM3/28/05
to
Hello,

I have a suggestion regarding [regexp] with -all option. According to
the documentation: "If this is specified with match variables, they
will contain information for the last match only."

My question is, wouldn't it be beneficient to include all matched
instances into the match variable instead of only the last one. The
match variable can be a list containing the matched instances or even
an array name.

So that using for instance:

regexp -all "\[0-9]+" "abc1def2...xyz9" match

we have the list {1 2 ... 9} inside the var match.

I think this will help especially in case that it is not easy to
predict the length of the "string" or how it is constructed, and we
need to match some keywords.

If others Tcl'ers see this useful as well, perhaps this enhancement can
be included in a future release. Or may be there are other (better)
ways, I'm not aware of, to perform the same task.

Thank u all for yr help and comments.

Rgrds
Khaled

Donald Arseneau

unread,
Mar 28, 2005, 6:02:31 AM3/28/05
to
"Khaled" <ks...@free.fr> writes:

> regexp -all "\[0-9]+" "abc1def2...xyz9" match
> we have the list {1 2 ... 9} inside the var match.

set match [regexp -all -inline "\[0-9]+" "abc1def2...xyz9"]


--
Donald Arseneau as...@triumf.ca

Khaled

unread,
Mar 28, 2005, 6:14:03 AM3/28/05
to
Thank you Donald !

0 new messages