The search operation scans the text widget for a string that matches a pattern. The index of the text that matches the pattern is returned. The search starts at an index and covers all the text widget unless a stop index is supplied. You can use end as the stop index to prevent the search from wrapping back to the beginning of the document. The general form of the search operation is this:
$t search ?options? pattern index ?stopIndex?
Table 33-4 summarizes the options to the search operation:
If you use a regular expression to match a pattern, you may be interested in how much text matched so you can highlight the match. The -count option specifies a variable that gets the number of matching characters:
set start [$t search -count cnt -regexp -- $pattern 1.0 end] $t tag add sel $start "$start +$cnt chars"
18.117.138.104