Regex to match date and initals
I have a regex which should find a string pattern of any of the following formats
28.05.2018 SB RS CS
28-05-2018 SB RS CS
28/05/2018 SB RS CS
The regular expressions matches the first example with the full stops in the date, but does not match the second and third example with the dashes and forward slashes in the date.
Can any one please advise how to correct the regular expression so that it matches a dash or a forward slash?
Any assistance will be most appreciated.
This is part of a script which matches the string and reports it back to the console.
var ckWords4; // 4 words to test
var re = new RegExp(/\d{1,2}[/.-]\d{1,2}[/.-]\d{2,4}\s([A-Z]{2,5})\s([A-Z]{2,5})\s([A-Z]{2,5})/);
var count; // count number of words
numWords = this.getPageNumWords(0); // number of words on page
// loop through the words on page
for (var j = 0; j < numWords-1; j++) {
ckWords4 = this.getPageNthWord(0, j) + ' ' + this.getPageNthWord(0, j + 1) + ' ' + this.getPageNthWord(0, j + 2) + ' ' + this.getPageNthWord(0, j + 3); // test 4 words if (ckWords4.match(re)) {
var count = ckWords4.split(/\s+/).length;
console.println(ckWords4 + " " + count);
}
}
