undead.regexp

Deprecated. It will be removed in February 2012. Please use std.regex instead.

Regular expressions are a powerful method of string pattern matching. The regular expression language used in this library is the same as that commonly used, however, some of the very advanced forms may behave slightly differently. The standard observed is the ECMA standard for regular expressions.

undead.regexp is designed to work only with valid UTF strings as input. To validate untrusted input, use std.utf.validate().

In the following guide, pattern[] refers to a regular expression. The attributes[] refers to a string controlling the interpretation of the regular expression. It consists of a sequence of one or more of the following characters:

<table border=1 cellspacing=0 cellpadding=5> <caption>Attribute Characters</caption>

AttributeAction

<tr>

gglobal; repeat over the whole input string

</tr> <tr>

icase insensitive

</tr> <tr>

mtreat as multiple lines separated by newlines

</tr> </table>

The format[] string has the formatting characters:

<table border=1 cellspacing=0 cellpadding=5> <caption>Formatting Characters</caption>

FormatReplaced With$$$$&amp;The matched substring.$`The portion of string that precedes the matched substring.$'The portion of string that follows the matched substring.$nThe nth capture, where n is a single digit 1-9 and $n is not followed by a decimal digit.$nnThe nnth capture, where nn is a two-digit decimal number 01-99. If nnth capture is undefined or more than the number of parenthesized subexpressions, use the empty string instead.

</table>

Any other $ are left as is.

References: Wikipedia

Members

Classes

RegExp
class RegExp

RegExp is a class to handle regular expressions.

RegExpException
class RegExpException

One of these gets thrown on compilation errors

Functions

find
sizediff_t find(string s, RegExp pattern)

Search s[] for first match with pattern.

find
sizediff_t find(string s, string pattern, string attributes)
pattern
Pattern!(Char) pattern(immutable(Char)[] pat)
Undocumented in source. Be warned that the author may not have intended to support it.
rfind
sizediff_t rfind(string s, RegExp pattern)

Search s[] for last match with pattern.

rfind
sizediff_t rfind(string s, string pattern, string attributes)
search
RegExp search(string s, string pattern, string attributes)

Search s[] for first match with pattern[] with attributes[].

split
string[] split(string s, RegExp pattern)

Split s[] into an array of strings, using the regular expression pattern as the separator.

split
string[] split(string s, string pattern, string attributes)
splitter
Splitter!(Range) splitter(Range r, Pattern!(char) pat)
Undocumented in source. Be warned that the author may not have intended to support it.
sub
string sub(string s, string pattern, string format, string attributes)

Search string for matches with regular expression pattern with attributes. Replace each match with string generated from format.

sub
string sub(string s, string pattern, string delegate(RegExp) dg, string attributes)

Search string for matches with regular expression pattern with attributes. Pass each match to delegate dg. Replace each match with the return value from dg.

Structs

Pattern
struct Pattern(Char)
Undocumented in source.
Splitter
struct Splitter(Range)
Undocumented in source.
regmatch_t
struct regmatch_t
Undocumented in source.

Variables

email
string email;

Regular expression to extract an email address. References: How to Find or Validate an Email Address
RFC 2822 Internet Message Format

url
string url;

Regular expression to extract a url

Meta

License

<a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.