O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 Search Options for more information.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required