text search
Finds a pattern in the content and gives the index of the first match.
PATHNAME search ?SWITCH ...? PATTERN INDEX ?STOPINDEX?
Description
Searches from INDEX forward, or backward with -backwards, up to STOPINDEX or around the whole content. Gives the index of the start of the first match, or an empty string. The switches are:
-forwardsand-backwards: the direction.-exactand-regexp: the kind of pattern. The default is-exact.-nocase: a match that ignores the case of the letters.-count VAR: sets VAR to the length of the match.-all: gives the index of each match.-nolinestop,-elide,-overlap, and-strictlimits: the rules of Tk for a regular expression across lines, elided text, overlaps, and STOPINDEX.--: ends the switches, for a PATTERN that starts with-.
Returns
An index, a list of indices with -all, or an empty string.
Examples
% text .sr
> .sr insert end "hello world\nline two"
> .sr search two 1.0
2.5
% text .sr2
> .sr2 insert end "Hello world"
> .sr2 search -nocase -count n WORLD 1.0
> set n
5
Errors
% text .sr3; .sr3 search
wrong # args: should be ".sr3 search ?switches? pattern index ?stopIndex?"
-errorcode NONE
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1