SJunejo
SJunejo

Reputation: 1336

Java regex To find start of string

Could you please help me with following as I do not want to waist any more time on it;

I have following code which is not working;

String someStr = "C:\SomeDir";
boolean = someStr.matches("(^[A-Z|a-z]:[\\\\:/])*"));

The above code is returning false, but it I think it should return 'true', am I missing anything? I just want to know if my string starts with C:\ or C:/ or :[/|]....

Thanks,

--

SJunejo

Upvotes: 0

Views: 156

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533472

Match is only true for an exact match as documented.

What you appear to want is

boolean root = someStr.matches("[A-Za-z]:[\\\\/].*");

Upvotes: 3

Related Questions