How do I do a case-insensitive replace all for a string?
The option to replace case insensitive regex in java is Pattern.CASE_INSENSITIVE, which can also be specified as (?i)
(http://boards.developerforce.com/t5/Apex-Code-Development/Why-Pattern-CASE-INSENSITIVE-not-detectable/td-p/204337)
String srcStr = '{!id} value {!Id} is not {!ID}';
String replaceToken = '(?i)\\{!id\\}';
System.debug('REPLACEMENT ' + srcStr.replaceAll(replaceToken, ''));
System.assertEquals(' value is not ', srcStr.replaceAll(replaceToken, ''));
Just curious can you not convert the string to a particular case?
say
String ex = 'Upper';
ex.toLowerCase();
(or)
ex.toUpperCase()
Examples from the official documentation -
String s1 = 'ThIs iS hArD tO rEaD';
System.assertEquals('this is hard to read',
s1.toLowerCase());
String myString1 = 'abcd';
String myString2 = 'ABCD';
myString1 =
myString1.toUpperCase();
Boolean result =
myString1.equals(myString2);
System.assertEquals(result, true);