NAME

Text::NestedMatch - Perl extension to find regexp delimited strings with proper nesting

SYNOPSIS

use Text::NestedMatch;

($match,$remainder) = nested_match($string, $startdelim, $enddelim);
$match              = nested_match($string, $startdelim, $enddelim);
$remainder          = skip_nested_match($string, $startdelim, $enddelim);

# Make the start and end delimiters case sensitive.  Off by default.
$Text::NestedMatch::case_sensitive = 1;

DESCRIPTION

These routines allow you to extract properly nested strings out of a larger string. The start and end delimiters are regular expressions. If the string does not begin with $startdelim, everything up to the first $startdelim will be included on the matched string.

nested_match

The nested_match() routine searches for a properly nested substring. It returns the match in a scalar context or both the match and the remainder in a list context.

skip_nested_match

The skip_nested_match() routine searches for a properly nested substring. It returns the remainder in a scalar context or both the match and the remainder in a list context.

EXAMPLES

($lispexpr, $rest) = nested_match ("(defun () (let ...)) (defun ...)",
                                   "(", ")");

would yield

$lispexpr eq '(defun () (let ...))'
$rest     eq ' (defun ...)';

and

$rest = skip_nested_match($dtd_fragment, '<UL>', '<\/UL>');

will skip over a <UL> element in an SGML document. Note that the backslash is quoted, the start and end delimiters are regular expressions.

AUTHOR

Norman Walsh, norm@berkshire.net

COPYRIGHT

Copyright (c) 1996, 1997 Norman Walsh. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl(1).