Francois Perrad > re-engine-Lua-0.10 > re::engine::Lua

Download:
re-engine-Lua-0.10.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.10   Source   Latest Release: re-engine-Lua-0.13

NAME ^

re::engine::Lua - Lua regular expression engine

SYNOPSIS ^

    use re::engine::Lua;

    if ('Hello, world' =~ /Hello, (world)/) {
        print "Greetings, $1!";
    }

DESCRIPTION ^

Replaces perl's regex engine in a given lexical scope with the Lua 5.2 one.

See "Lua 5.2 Reference Manual", section 6.4.1 "Patterns", http://www.lua.org/manual/5.2/manual.html#6.4.1.

Character Class:

A character class is used to represent a set of characters. The following combinations are allowed in describing a character class:

x

(where x is not one of the magic characters ^$()%.[]*+-?) represents the character x itself.

.

(a dot) represents all characters.

%a

represents all letters.

%c

represents all control characters.

%d

represents all digits.

%g

represents all printable characters except space.

%l

represents all lowercase letters.

%p

represents all punctuation characters.

%s

represents all space characters.

%u

represents all uppercase letters.

%w

represents all alphanumeric characters.

%x

represents all hexadecimal digits.

%z DEPRECATED

represents the character with representation 0.

%x

(where x is any non-alphanumeric character) represents the character x. This is the standard way to escape the magic characters. Any punctuation character (even the non magic) can be preceded by a '%' when used to represent itself in a pattern.

[set]

represents the class which is the union of all characters in set. A range of characters can be specified by separating the end characters of the range, in ascending order, with a '-'. All classes %x described above can also be used as components in set. All other characters in set represent themselves. For example, [%w_] (or [_%w]) represents all alphanumeric characters plus the underscore, [0-7] represents the octal digits, and [0-7%l%-] represents the octal digits plus the lowercase letters plus the '-' character.

The interaction between ranges and classes is not defined. Therefore, patterns like [%a-z] or [a-%%] have no meaning.

[^set]

represents the complement of set, where set is interpreted as above.

For all classes represented by single letters (%a, %c, etc.), the corresponding uppercase letter represents the complement of the class. For instance, %S represents all non-space characters.

The definitions of letter, space, and other character groups depend on the current locale. In particular, the class [a-z] may not be equivalent to %l.

Pattern Item:

A pattern item can be

Pattern:

A pattern is a sequence of pattern items. A caret '^' at the beginning of a pattern anchors the match at the beginning of the subject string. A '$' at the end of a pattern anchors the match at the end of the subject string. At other positions, '^' and '$' have no special meaning and represent themselves.

Captures:

A pattern can contain sub-patterns enclosed in parentheses; they describe captures. When a match succeeds, the substrings of the subject string that match captures are stored (captured) for future use. Captures are numbered according to their left parentheses. For instance, in the pattern "(a*(.)%w(%s*))", the part of the string matching "a*(.)%w(%s*)" is stored as the first capture (and therefore has number 1); the character matching "." is captured with number 2, and the part matching "%s*" has number 3.

As a special case, the empty capture () captures the current string position (a number). For instance, if we apply the pattern "()aa()" on the string "flaaap", there will be two captures: 3 and 5. NOT SUPPORTED BY re::engine::Lua, the two captures are empty string, the position are available in @- and @+ as usually.

AUTHOR ^

François PERRAD <francois.perrad@gadz.org>

HOMEPAGE ^

The development is hosted at https://github.com/fperrad/re-engine-lua.

LICENSE AND COPYRIGHT ^

Copyright 2007-2013 François PERRAD.

This program is free software; you can redistribute it and/or modify it under the same terms as Lua.

The code fragment from original Lua 5.2.0 is under a MIT license, see http://www.lua.org/license.html#5.

syntax highlighting: