I have strings of a particular pattern as below which i need to validate:
String a ="test/<value>"
String b = "test/test1/<value>"
String c = "test3";
String d = "test4"
where value - can be any thing i.e alphabets,numeric,symbol,spl characters.
String c and String d are pretty straight forward.The issue comes for string a,b.
Valid Strings:
test/12 | test/abc | test/12.39 ...
test/test1/12 | test/test1/abc | test/test1/12.30
test3
test4
Invalid Strings:
test1/12
test/test123/12
test,test1,test3,test4 are key words. any change in that should return me false.
I tried with the below regex pattern:
Pattern pattern1 = "^(test/(test1/)?[A-Za-z0-9]+|test3|test4)?/?$"
it works fine for few scenario's i.e
test/123 (pass)
test/test1/abc123(pass)
It fails when it has any symbol,decimal value or spl characters:
test/10.12 (Fail)
test/test1/@#$$ (Fail)
Pattern pattern2 = "^(test/(test1/)?[A-Za-z0-9/*!@#$%^&*()\"{}_|\\?/<>,.]+|test3|test4)?/?$";
When i use the above pattern if there are any change in the keyword it fails.
test/test1344/123(Fail)
i.e even if i change the keyword it returns as true.Expected result is false.
Please advice as to how i can validate the above strings ?