Search code examples
javareplaceall

Replacing certain combination of characters


I'm trying to remove the first bad characters (CAP letter + dot + Space) of this.

A. Shipping Length of Unit
C. OVERALL HEIGHT
Overall Weigth
X. Max Cutting Height

I tried something like that, but it doesn't work:

string.replaceAll("[A-Z]+". ", "");

The result should look like this:

Shipping Length of Unit
OVERALL HEIGHT
Overall Weigth
Max Cutting Height


Solution

  • This should work:

    string.replaceAll("^[A-Z]\\. ", "")
    

    Examples

    "A. Shipping Length of Unit".replaceAll("^[A-Z]\\. ", "")
    // => "Shipping Length of Unit"
    "Overall Weigth".replaceAll("^[A-Z]\\. ", "")
    // => "Overall Weigth"