Captures

Captures object contains submatches captured during a call to match or iteration over RegexMatch range.

First element of range is the whole match.

Members

Functions

opCast
bool opCast()

Explicit cast to bool. Useful as a shorthand for !(x.empty) in if and assert statements.

opIndex
inout(R) opIndex(size_t i)

Range interface.

opIndex
R opIndex(String i)

Lookup named submatch.

popBack
void popBack()
popFront
void popFront()
back
R back [@property getter]

Range interface.

Properties

captures
ref captures [@property getter]

A hook for compatibility with original std.regex.

empty
bool empty [@property getter]

Range interface.

front
R front [@property getter]

Range interface.

hit
R hit [@property getter]

Slice of matched portion of input.

length
size_t length [@property getter]

Number of matches in this object.

post
R post [@property getter]

Slice of input immediately after the match.

pre
R pre [@property getter]

Slice of input prior to the match.

whichPattern
int whichPattern [@property getter]

Number of pattern matched counting, where 1 - the first pattern. Returns 0 on no match.

Examples

import std.range.primitives : popFrontN;

auto c = matchFirst("@abc#", regex(`(\w)(\w)(\w)`));
assert(c.pre == "@"); // Part of input preceding match
assert(c.post == "#"); // Immediately after match
assert(c.hit == c[0] && c.hit == "abc"); // The whole match
assert(c[2] == "b");
assert(c.front == "abc");
c.popFront();
assert(c.front == "a");
assert(c.back == "c");
c.popBack();
assert(c.back == "b");
popFrontN(c, 2);
assert(c.empty);

assert(!matchFirst("nothing", "something"));

// Captures that are not matched will be null.
c = matchFirst("ac", regex(`a(b)?c`));
assert(c);
assert(!c[1]);

Meta