I’ve got the regexes working in Javascript, now I want to translate these to Java:
var nat_pattern2 = /^\d{8}$/;
var nat_pattern2 = /^\d{7}\-\d{1}$/;
var pct_pattern1 = /^\PCT\/?[A-Z]{2}?\d{4}\/\d{6}$/;
var ing pct_pattern2 = /^\PCT[A-Z]{2}\d{10}$/;
var pct_pattern3 = /^\P[A-Z]{2}\d{8}$/;
var its_pattern1 = /^\ITS\/?[A-Z]{2}?\d{2}\/\d{5}$/;
var its_pattern2 = /^\ITS[A-Z]{2}\d{7}$/;
var its_pattern3 = /^\I[A-Z]{2}\d{7}$/;
My beginning looks something like this but it is not correct:
Pattern pattern = Pattern.compile("/^\d{8}$/");
Can you help me?
You don’t need the
/around your regexp in Java.\das to be escaped in order to be part of the String defining the regex so it will become\\d.Slashes have no special meanings and so don’t need to be escaped too.