View source code
Display the source code in std/regex.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
std.regex.regex
- multiple declarations
- Function regex
- Alias Regex
Function regex
Compile regular expression pattern
for the later execution.
Prototype
auto regex(S)( S pattern, const(char)[] flags = "" ) @trusted if (isSomeString!S);
Returns
Regex
object
that works on inputs having
the same character width as
.
pattern
Parameters
Name | Description |
---|---|
pattern | Regular expression |
flags | The attributes (g, i, m and x accepted) |
Throws
if there were any errors during compilation.
RegexException
Alias Regex
Regex
object
holds regular expression pattern in compiled form.
Instances of this object
are constructed via calls to
.
This is an intended form for caching and storage of frequently
used regular expressions.
regex
Declaration
alias Regex(Char) = std. regex. internal. ir. Regex!Char
;
Examples
Test if this object
doesn't contain any compiled pattern.
Regex!char r; assert(r.empty); r = regex(""); // Note: "" is a valid regex pattern. assert(!r.empty);
Getting a range of all the named captures in the regex
.
import std.range;
import std.algorithm;
auto re = regex((?P<name>\w+) = (?P<var>\d+)
);
auto nc = re.namedCaptures;
static assert(isRandomAccessRange!(typeof(nc)));
assert(!nc.empty);
assert(nc.length == 2);
assert(nc.equal(["name", "var"]));
assert(nc[0] == "name");
assert(nc[1..$].equal(["var"]));
Authors
Dmitry Olshansky,
API and utility constructs are modeled after the original
by Walter Bright and Andrei Alexandrescu.
std.regex