Thread overview
case insensitive flag not working with replaceAll
Jan 02, 2014
Tyler
Jan 02, 2014
Brad Anderson
Jan 03, 2014
Tyler
January 02, 2014
Hi, I'm having issues with the case insensitive flag from the phobos regex library (2.064). I have the following line of code which returns a string. Consider the following inputs...
fileLine = "policy PRI-GROUPJ-EXPORT"
redTerm = "groupj"

  auto newString = replaceAll!(replaceTerm)(fileLine, regex(redTerm, "gi"));

The code will not match the redTerm "groupj", even though I have the case insensitive flag "i" set. If the redTerm text is "GROUPJ", it will match and return the correctly modified string.

Am I using this incorrectly?
January 02, 2014
On Thursday, 2 January 2014 at 15:11:55 UTC, Tyler wrote:
> Hi, I'm having issues with the case insensitive flag from the phobos regex library (2.064). I have the following line of code which returns a string. Consider the following inputs...
> fileLine = "policy PRI-GROUPJ-EXPORT"
> redTerm = "groupj"
>
>   auto newString = replaceAll!(replaceTerm)(fileLine, regex(redTerm, "gi"));
>
> The code will not match the redTerm "groupj", even though I have the case insensitive flag "i" set. If the redTerm text is "GROUPJ", it will match and return the correctly modified string.
>
> Am I using this incorrectly?

It's working fine for me.

    import std.regex, std.stdio;

    void main()
    {
        auto fileLine = "policy PRI-GROUPJ-EXPORT";
        auto redTerm = "groupj";

        writeln(fileLine);
        auto newString = replaceAll!(term => "replaced")(fileLine,
                             regex(redTerm, "gi"));
        writeln(newString);
    }

Output:
    policy PRI-GROUPJ-EXPORT
    policy PRI-replaced-EXPORT

Sidenote: The 'g' flag doesn't do anything if you are using the [match/replace][All/First] functions (and is actually deprecated because it's confusing).
January 03, 2014
Thanks for the response and assistance.

I was using the function incorrectly, I/O error ;).