Daniel Shane > Regexp-Extended-0.01 > Regexp::Extended

Download:
Regexp-Extended-0.01.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.01   Source  

NAME ^

Regexp::Extended - Perl wrapper that extends the re module with new features.

SYNOPSIS ^

  use Regexp::Extended qw(:all);

  # (?<>...): named parameters 
  $date =~ /(?<year>\d+)-(?<month>\d+)-(?<day>\d+)/;
  if ("2002-10-30" =~ /$date/) {
    print "The date is : $::year->[0]-$::month->[0]-$::day->[0]\n";
  }
  
  # You can also access individial matches in ()* or ()+
  "1234" =~ /(?<digit>\d)+/;
  print "Digit 1 is : $::digit->[0]\n";
  print "Digit 2 is : $::digit->[1]\n";
  ...

  # You can also modify individual matches
  "1234" =~ /(?<digit>\d)+/;
  $::digit->[0] = 99;
  $::digit->[1] = 88;
  print "Modified string is: " . rebuild("1234"); # "998834"

  # (?*...): upto a certain pattern
  $text = "this is some <i>italic</i> text";
  $text =~ /<i>((?*</i>))</i>/;  # $1 = "italic"

  # (?+...): upto and including a certain pattern
  $text = "this is some <i>italic</i> text";
  $text =~ /(<i>(?+</i>))/;  # $1 = "<i>italic</i>"

  # You can also use fonctions inside patterns:

  sub foo {
    return "foo";
  }

  "foo bar" =~ /((?&foo()))/; # $1 => "foo"

DESCRIPTION ^

Rexexp::Extended is a simple wrapper arround the perl rexexp syntax. It uses the overload module to parse constant qr// expressions and substitute known operators with an equivalent perl re.

ADDED FEATURES ^

named parameters: (?<var>...)

The new construct: (?<var>pattern) will match pattern and if successfull will set a numeric parameters ($1, $2, ...) as well as a named parameter ($var). The parameter is called $::var or $var if you imported Regexp::Extended with qw(:all).

function dereferencing: (?&func(...))

The new construct: (?&function(...)) will be replaced by the result of the call to function(...). Note that the result of the call will not be evaluated for named parameters of additionnal function calls.

upto constructs: (?*...) and (?+...)

The new construct: (?*pattern) will be rewritten as follow: (?:(?!pattern).)*

You could also write is as (?&upto(pattern)) if you import Regexp::Extended with qw(:all).

This basically matches upto a certain pattern (or includes it in the latter).

EXPORTED FUNCTIONS ^

rxt($string), rxt($string)

This function parses a string (or pattern) and returns the transformed version according the the above operators.

AUTHOR ^

Daniel Shane, <lachinois@hotmail.com>

SEE ALSO ^

Regexp::Fields for yet another way of extending the perl re engine by patching it.

syntax highlighting: