Issues with std.regex

Dmitry Olshansky dmitry.olsh at gmail.com
Sun Feb 17 07:34:23 PST 2013


17-Feb-2013 01:36, MrAppleseed пишет:
> On Saturday, 16 February 2013 at 20:33:15 UTC, FG wrote:
>> On 2013-02-16 21:22, MrAppleseed wrote:
>>> auto reg = regex("[ 0-9a-zA-Z.*=+-;()\"\'\[\]<>,{}^#/\\]");
>>>
>>> When I try to run the code above, I get:
>>> parser.d(64): Error: undefined escape sequence \[
>>> parser.d(64): Error: undefined escape sequence \]
>>>
>>> When I remove the escaped characters (turning my regex into
>>> "[ 0-9a-zA-Z.*=+-;()\"\'[]<>,{}^#/\\]"), I get no issues compiling or
>>> linking.

Like others noted the problem is 2-fold:

- escaping special characters (both as D string literla and regex 
escaping itself). So just use `` or r"" or some form of WYSIWYG string 
*AND* do escaping for things that are part of regex syntax.

- [] are used for nesting, as std.regex supports set-wise operations 
inside of [...] character class e.g.
[[A-Z]&&[A-D]]
means intersection and would yield a set of [A-D]. It gets more useful 
with Unicode character sets.


-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list