www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - case insensitive flag not working with replaceAll

reply "Tyler" <sprizzer gmail.com> writes:
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?
Jan 02 2014
parent reply "Brad Anderson" <eco gnuk.net> writes:
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).
Jan 02 2014
parent "Tyler" <sprizzer gmail.com> writes:
Thanks for the response and assistance.

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