Text::Balanced

Extract delimited text sequences from strings
Download

Text::Balanced Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Damian Conway
  • Publisher web site:
  • http://search.cpan.org/~dconway/

Text::Balanced Tags


Text::Balanced Description

Extract delimited text sequences from strings Text::Balanced is a Perl module to extract delimited text sequences from strings.SYNOPSIS use Text::Balanced qw ( extract_delimited extract_bracketed extract_quotelike extract_codeblock extract_variable extract_tagged extract_multiple gen_delimited_pat gen_extract_tagged ); # Extract the initial substring of $text that is delimited by # two (unescaped) instances of the first character in $delim. ($extracted, $remainder) = extract_delimited($text,$delim); # Extract the initial substring of $text that is bracketed # with a delimiter(s) specified by $delim (where the string # in $delim contains one or more of '(){}[]'). ($extracted, $remainder) = extract_bracketed($text,$delim); # Extract the initial substring of $text that is bounded by # an XML tag. ($extracted, $remainder) = extract_tagged($text); # Extract the initial substring of $text that is bounded by # a C...C pair. Don't allow nested C tags ($extracted, $remainder) = extract_tagged($text,"BEGIN","END",undef,{bad=>}); # Extract the initial substring of $text that represents a # Perl "quote or quote-like operation" ($extracted, $remainder) = extract_quotelike($text); # Extract the initial substring of $text that represents a block # of Perl code, bracketed by any of character(s) specified by $delim # (where the string $delim contains one or more of '(){}[]'). ($extracted, $remainder) = extract_codeblock($text,$delim); # Extract the initial substrings of $text that would be extracted by # one or more sequential applications of the specified functions # or regular expressions @extracted = extract_multiple($text, */, 'literal', ]);# Create a string representing an optimized pattern (a la Friedl) # that matches a substring delimited by any of the specified characters # (in this case: any type of quote or a slash) $patstring = gen_delimited_pat(q{'"`/});# Generate a reference to an anonymous sub that is just like extract_tagged # but pre-compiled and optimized for a specific pair of tags, and consequently # much faster (i.e. 3 times faster). It uses qr// for better performance on # repeated calls, so it only works under Perl 5.005 or later. $extract_head = gen_extract_tagged('< HEAD >','< /HEAD >'); ($extracted, $remainder) = $extract_head->($text);The various extract_... subroutines may be used to extract a delimited substring, possibly after skipping a specified prefix string. By default, that prefix is optional whitespace (/s*/), but you can change it to whatever you wish (see below).The substring to be extracted must appear at the current pos location of the string's variable (or at index zero, if no pos position is defined). In other words, the extract_... subroutines don't extract the first occurrence of a substring anywhere in a string (like an unanchored regex would). Rather, they extract an occurrence of the substring appearing immediately at the current matching position in the string (like a G-anchored regex would). Requirements: · Perl


Text::Balanced Related Software