var sstring = "my half day leave for 3rd december"; //"on jan 10 apply leave";
var smonth = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
var lmonth = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
var monthno = -1;
// works for check for 13th Apil , 13 april , 13 april 2015
var reg = /\b\s*(\d*)\s*(?:st|th|nd|rd)*\s* (?:(?:jan|feb)?r?(?:uary)?|mar(?:ch)?|apr(?:il)?|may|june?|july?|aug(?:ust)?|oct(?:ober)?|(?:sept?|nov|dec)(?:ember)?)\s*(\d*)(?:st|th|nd|rd)*\s* (\d*)/ig
var test = sstring.match(reg)
alert(test);
test = test.join("").trim();
// extract month name here
var reg1 = /(?!th|st|nd) \s*[a-zA-z]+/ig;
var month = test.match(reg1).join("").trim();
if (month)
{
monthno = smonth.indexOf(month) + 1;
if (!monthno)
{ console.log(monthno);
monthno = lmonth.indexOf(month) + 1;
}
}
// logic to fetch date else current Year
var reg2 = /\d{4}/ig;
var year = test.match(reg2);
if (!year)
{
year = new Date().getFullYear();
}
var reg3 = /(\b\d{1,2}(?:st|nd|th)?\s)/ig;
var date1 = test.match(reg3).join("");
var reg4 = /\b\d{1,2}/ig
var date = date1.match(reg4).join("").trim();
console.log("Final date parsed => ");
console.log(date+"/"+monthno+"/"+year);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.