Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function matchDates(input){
- let dateMatchPattern = /\b\d{1,2}-\w{3}-\d{4}\b/g;
- for (let element of input) {
- if (dateMatchPattern.test(input)) {
- let date = element.match(dateMatchPattern).toString();
- let day = date.split(/[-]+/)[0].trim();
- let month = date.split(/[-]+/)[1];
- let year = date.split(/[-]+/)[2];
- console.log(`${date} (Day: ${day}, Month: ${month}, Year: ${year})`);
- }
- }
- }
- matchDates(['I am born on 30-Dec-1994.'])
- matchDates(['This is not date: 512-Jan-1996.'])
- matchDates(['My father is born on the 29-Jul-1955.'])
- matchDates(['1-Jan-1999 is a valid date.']);
- matchDates(['So is 01-July-2000.']);
- matchDates(['I am an awful liar, by the way -- Ivo, 28-Sep-2016.']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement