F
frosted74
Hi,
I am trying to use a Pattern to match certain strings in error
messages in our application. We are delimiting them using the
following notation, {0}, {1}, etc. I am trying to use String's
replaceFirst (even replaceAll) method to replace the instances of
these tokens with appropriate Strings. I am using the following code:
String match = "\\{0\\}";
String message = "{0} should be 5 characters in length.";
String replacement = "Zip Code";
message.replaceAll( match, replacement );
message is unaffected by this method call.
This pattern /\{0\}/ works on online RegEx testers, but I feel I am
missing an important step porting it to java's Pattern class. I have
tried sticking /'s into the string, ending it with "g", etc. Nothing
seems to work. anyone have any insight into how I can do this or what
I am doing incorrectly?
TIA.
I am trying to use a Pattern to match certain strings in error
messages in our application. We are delimiting them using the
following notation, {0}, {1}, etc. I am trying to use String's
replaceFirst (even replaceAll) method to replace the instances of
these tokens with appropriate Strings. I am using the following code:
String match = "\\{0\\}";
String message = "{0} should be 5 characters in length.";
String replacement = "Zip Code";
message.replaceAll( match, replacement );
message is unaffected by this method call.
This pattern /\{0\}/ works on online RegEx testers, but I feel I am
missing an important step porting it to java's Pattern class. I have
tried sticking /'s into the string, ending it with "g", etc. Nothing
seems to work. anyone have any insight into how I can do this or what
I am doing incorrectly?
TIA.