| |
 | Posted by Brad Anderson in reply to Tyler | Permalink Reply |
|
Brad Anderson 
| 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).
|