The class UpperCaseConverter converts the input text into uppercase text excluding the word matched to regEx "(?i)^((?!sht).)*".
What I expected to get is 1A0A-50-CRD-140-20002-063484C-N-01_Sht_1A.pdf but the result is 1A0A-50-CRD-140-20002-063484C-N-01_Sht_1a.pdf.
How could the last part of the letter be uppercase except for the .pdf
UpperCaseConverter
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class UpperCaseConverter {
private UpperCaseConverter(){};
public static String convert(String text, String regEx) {
StringBuilder toBeConverted = new StringBuilder(text);
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(toBeConverted);
while(matcher.find()) {
String buf = toBeConverted.substring(matcher.start(), matcher.end()).toUpperCase();
toBeConverted.replace(matcher.start(), matcher.end(), buf);
}
return toBeConverted.toString();
}
}
*TestCase
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class UpperCaseConverterTest {
@Test
public void testUpperCase() {
String expect = UpperCaseConverter.convert("1a0A-50-CRD-140-20002-063484C-N-01_Sht_1a.pdf",
"(?i)^((?!sht).)*");
assertEquals("1A0A-50-CRD-140-20002-063484C-N-01_Sht_1A.pdf", expect);
}
}