-2

Is there a way to extract only date part from this string if the other text is not fixed:

Input: "6/27/2014 - is Today" Expected: "6/27/2014"

Pawan
  • 605
  • 1
  • 6
  • 18

2 Answers2

3

Try the following snippet:

var input = "6/27/2014 - is Today";
var expected = input.match(/\d{1,2}\/\d{1,2}\/\d{4}/)[0];
console.log(expected);
ntalbs
  • 28,700
  • 8
  • 66
  • 83
0

If that's the format all the time then you can also try .split() method

var date = "6/27/2014 - is Today".split(" ");
console.log(date[0]);
NcDreamy
  • 785
  • 6
  • 14