Searching the Contents of a Text Widget
You can use the search method to search the Text widget for a pattern or regular expression. The search method takes some optional switches, the pattern to search for, and an index at which to start searching:
$index = $text->search([switches], pattern, index, [ stopindex ])
If a match is made, the index returned points to the first character in the match. If no match is made, an empty string is returned.
Here is a simple example of using search:
$result = $text->search(-backwards => "find me", 'end'); $location = $text->search(-nocase => "SWITCHES", "1.0");
See the sidebar "Search Options" for more information.
Search Options
-forwards- Tells
searchto search forward through the Text widget starting at. This is the default.index-backwards- Tells
searchto search backward through the Text widget starting at the character before.index-exact- The
must match the text exactly. This is the default.pattern-regexp- The
will be considered as a regular expression.pattern-nocase- Ignores case between
and the text within the Text widget.pattern-hidden- Searches text even if it has a tag with
-state => hidden.-count => varnameis a pointer to a variable (i.e.,varname$variable). The number of characters matched will be stored within that variable.--- This option does nothing except force the next argument to be taken as the
even if the next string starts with apattern"-".