Regex object holds regular expression pattern in compiled form.
Exception object thrown in case of errors during regex compilation.
A StaticRegex is Regex object that contains D code specially generated at compile-time to speed up matching.
Compile regular expression using CTFE and generate optimized native machine code for matching it.
Start matching of input to regex pattern re, using traditional backtracking matching scheme.
A range that lazily produces a string output escaped to be used inside of a regular expression.
Start matching input to regex pattern re, using Thompson NFA matching scheme.
Initiate a search for all non-overlapping matches to the pattern re in the given input. The result is a lazy range of matches generated as they are encountered in the input going left to right.
Find the first (leftmost) slice of the input that matches the pattern re. This function picks the most suitable regular expression engine depending on the pattern properties.
Compile regular expression pattern for the later execution.
Old API for replacement, operation depends on flags of pattern re. With "g" flag it performs the equivalent of replaceAll otherwise it works the same as replaceFirst.
Construct a new string from input by replacing all of the fragments that match a pattern re with a string generated from the match according to the format specifier.
This is a general replacement tool that construct a new string by replacing matches of pattern re in the input. Unlike the other overload there is no format string instead captures are passed to to a user-defined functor fun that returns a new string to use as replacement.
A variation on replaceAll that instead of allocating a new string on each call outputs the result piece-wise to the sink. In particular this enables efficient construction of a final output incrementally.
Construct a new string from input by replacing the first match with a string generated from it according to the format specifier.
This is a general replacement tool that construct a new string by replacing matches of pattern re in the input. Unlike the other overload there is no format string instead captures are passed to to a user-defined functor fun that returns a new string to use as replacement.
A variation on replaceFirst that instead of allocating a new string on each call outputs the result piece-wise to the sink. In particular this enables efficient construction of a final output incrementally.
An eager version of splitter that creates an array with splitted slices of input.
Splits a string r using a regular expression pat as a separator.
Captures object contains submatches captured during a call to match or iteration over RegexMatch range.
A regex engine state, as returned by match family of functions.
Splits a string r using a regular expression pat as a separator.
Copyright Dmitry Olshansky, 2011-
Regular expressions are a commonly used method of pattern matching on strings, with regex being a catchy word for a pattern in this domain specific language. Typical problems usually solved by regular expressions include validation of user input and the ubiquitous find & replace in text processing utilities.
Synopsis
Syntax and general information
The general usage guideline is to keep regex complexity on the side of simplicity, as its capabilities reside in purely character-level manipulation. As such it's ill-suited for tasks involving higher level invariants like matching an integer number $(U bounded) in an [a,b] interval. Checks of this sort of are better addressed by additional post-processing.
The basic syntax shouldn't surprise experienced users of regular expressions. For an introduction to std.regex see a short tour of the module API and its abilities.
There are other web resources on regular expressions to help newcomers, and a good reference with tutorial can easily be found.
This library uses a remarkably common ECMAScript syntax flavor with the following extensions:
std.regex operates on codepoint level, 'character' in this table denotes a single Unicode codepoint.
Unicode support
This library provides full Level 1 support* according to UTS 18. Specifically:
*With exception of point 1.1.1, as of yet, normalization of input is expected to be enforced by user.
Replace format string
A set of functions in this module that do the substitution rely on a simple format to guide the process. In particular the table below applies to the format argument of replaceFirst and replaceAll.
The format string can reference parts of match using the following notation.
Slicing and zero memory allocations orientation
All matches returned by pattern matching functionality in this library are slices of the original input. The notable exception is the replace family of functions that generate a new string from the input.
In cases where producing the replacement is the ultimate goal replaceFirstInto and replaceAllInto could come in handy as functions that avoid allocations even for replacement.