lundi 30 mars 2015

Java: Regex not matching

I have comma separated string values. Every string may contain characters or numbers along with '-' or '/' or '.'.


My code looks like:



final String VALUES_REGEX = "^\\{([0-9a-zA-Z\\-\\_\\.])+,*([0-9a-zA-Z\\-\\_\\.])*\\}$";
final Pattern REGEX_PATTERN = Pattern.compile(VALUES_REGEX);
final String values = "{df1_apx.fhh.irtrs.d.rrr, ffd1-afp.farr.d.rrr.asgd}";
final Matcher matcher = REGEX_PATTERN.matcher(values);
if (null != values && matcher.matches()) {
// further logic
}
...
...


Here if condition always returns false value because regex match fails. I verified regex using regexper. It looks fine.


Can you please tell me what is wrong here?


Aucun commentaire:

Enregistrer un commentaire