X|Y | alternation, i.e. X or Y |
(X) | matching brackets - creates a sub-match |
(?X) | non-matching brackets - only groups X, no sub-match is created |
[Z] | character class specification, Z is a string of characters or character ranges, e.g. [a-zA-Z0-9.\-] |
[^Z] | negated character class specification |
<X | lookbehind, X may be a single character or a character class |
>X | lookahead, X may be a single character or a character class |
^ | start of input or start of line |
$ | end of input or end of line |
\b | start or end of word, equals (?<\s>\S|<\S>\s) |
\B | opposite of \b, equals (?<\S>\S|<\s>\s) |
X? | zero or one |
X* | zero or more |
X+ | one or more |
X{n,m} | at least n, at most m instances of X. If n is missing, it's set to 0. If m is missing, it is set to infinity. |
X?? | non-greedy version of the above operators |
X*? | see above |
X+? | see above |
X{n,m}? | see above |
. | any printable character |
\s | whitespace |
\S | non-whitespace |
\w | alpha-numeric characters or underscore |
\W | opposite of \w |
\d | digits |
\D | non-digit |
const(char_t)[] pattern | Regular expression. |
auto r = new Regex("pattern"); auto s = new Regex(r"p[1-5]\s*");
const(char_t)[] pattern | Regular expression. |
auto r = Regex("pattern"); auto s = Regex(r"p[1-5]\s*");
import tango.io.Stdout; import tango.text.Regex; void main() { foreach(m; Regex("ab").search("qwerabcabcababqwer")) Stdout.formatln("{}[{}]{}", m.pre, m.match(0), m.post); } // Prints: // qwer[ab]cabcababqwer // qwerabc[ab]cababqwer // qwerabcabc[ab]abqwer // qwerabcabcab[ab]qwer
import tango.io.Stdout; import tango.text.Regex; void main() { auto strs = Regex("ab").split("abcabcababqwer"); foreach( s; strs ) Stdout.formatln("{}", s); } // Prints: // c // c // qwer