Tcl Package Commands


NAME

nreforeach - Iterate over all the regular expression matches in a string

SYNOPSIS

package require nre ?3.0?
nreforeach varname regexp string body

DESCRIPTION

The nreforeach command implements a loop where the loop variable varname takes on values from each match of regexp on string. The body argument is a Tcl script. For each match varname is assigned the text that regexp matched in string and then calls the Tcl interpreter to execute body.

If regexp contains ``()'' then each captured string will be lappended to varname. You can keep a subexpression from being appended by using ``(?:)'' instead of ``()''.

See the nrematch man page for a description of regular expressions. nreforeach is implemented using the nrematch command with the -eval -all and -flatten switches. See the nrematch for details on how you can create your own version of nreforeach with additional features.

KEYWORDS

iteration, looping, nre, regular expression, string

Last change: 3.0

[ nre3.0 ]

Copyright © 1997 Darrel Schneider.