I have a requirement which states as below
The following special characters are allowed with restrictions in the input string:
. ""(),:;<>@[\]The restrictions for the special characters are that they must only be used when contained between quotation marks.
For a simple test for ":" within input string, I wrote code as below:
private static void testEmailPattern() {
String email = "Test\":\"mail";
String PATTERN = "[\":\"]*";
boolean isValidEmail = email.matches(PATTERN);
System.out.println("Status: " + isValidEmail);
}
but this code returns false as opposed to true.
Edit: After reading comments, I modified that code to this, but it is still showing false.
I modified my code and made it as below:
public class TestFeatures {
private Pattern pattern;
private Matcher matcher;
private static final String PATTERN = "[.*\":\".*]*";
public TestFeatures() {
initEmailPattern();
}
private void initEmailPattern() {
pattern = Pattern.compile(PATTERN);
}
public boolean validate(final String hex) {
matcher = pattern.matcher(hex);
return matcher.matches();
}
/**
* @param args
*/
public static void main(String[] args) {
testEmailPattern();
}
private static void testEmailPattern() {
String email = "Test\":\"[email protected]";
TestFeatures thisClazz = new TestFeatures();
boolean isValidEmail = thisClazz.validate(email);
System.out.println("Status: " + isValidEmail);
}
}

matches()(or add.*at the beginning and the end of your regex).matches: "[t]ells whether or not this string matches the given regular expression".