Angelina Angelina - 1 year ago 146
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]:", "");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download