Angelina Angelina - 11 months ago 108
Java Question

Regex to strip Drive letter

I am trying to check if there is a

followed by
in my string.

If so, strip both.


This is what I have so far:

if(Pattern.matches("[a-zA-Z]:", path))
path = path.substring(2);

Does anyone have a better idea on how to accomplish this?

Answer Source

You can use:

path = path.replaceAll("^[a-zA-Z]:", "");