regex with literal (ie automatically replace '(' with '\(', etc) )
Dmitry Olshansky
dmitry.olsh at gmail.com
Thu May 30 09:25:17 PDT 2013
30-May-2013 14:24, Timothee Cour пишет:
> > According to this: http://dlang.org/phobos/std___regex.html#.replace
> <http://dlang.org/phobos/std_regex.html#.replace> you can use the same
> escape sequences for both (\c -> c in the replacement string).
>
> Your suggestion does not work; try for yourself by replacing the $$ by
> \$ in my code. Is that a bug in std.regex' doc?
> eg:
> replace("",regex(``),`\$`);
> => invalid format string in regex replace
>
Indeed replace format string is a different beast. I can't recall if I
stolen the original std.regex or devised this $$ myself.
By any rate replace(fmt, `\$`, "$$") would work or the same with replace
from std.string. So I feel it's a bit of stretch to include a function
for such a narrow case.
> However everything works fine with $$, see my code above.
>
> On Thu, May 30, 2013 at 1:14 AM, Diggory <diggsey at googlemail.com
> <mailto:diggsey at googlemail.com>> wrote:
>
> On Thursday, 30 May 2013 at 06:50:06 UTC, Timothee Cour wrote:
>
> ok, here it is:
>
> https://github.com/__timotheecour/dtools/blob/__master/dtools/util/util.d#L78
> <https://github.com/timotheecour/dtools/blob/master/dtools/util/util.d#L78>
> simplified implementation and added missing escape symbols. Any
> symbol
> missing?
> I was basing myself based on
> http://dlang.org/phobos/std___regex.html
> <http://dlang.org/phobos/std_regex.html>, table
> entry '\c where c is one of', but that was incomplete. I'm also
> noting that
> table entry 'any character except' is also incomplete.
>
> Technically any working "escapeRegex" would also function as
> a valid
>
> "escapeRegexReplace", although it might be slightly faster to have a
> specialised one.
>
> not sure, because they escape differently (\$ vs $$).
>
>
> According to this: http://dlang.org/phobos/std___regex.html#.replace
> <http://dlang.org/phobos/std_regex.html#.replace> you can use the
> same escape sequences for both (\c -> c in the replacement string).
>
>
--
Dmitry Olshansky
More information about the Digitalmars-d-learn
mailing list