-1

I really don't understand regex boundaries..

Why does this not work? My guess is the boundary isn't correct but I cant figure out why

    var dateInfo = `       This project was

                created on 09/02/2016

                     and last updated 10 days ago.`; 
    var regexString = '/This project was[\s]+ created on ([0-9]{2})\/([0-9]{2})\/([0-9]{4})[\s]+and last updated ([0-9]+) ([a-zA-Z]+)/im';
    var arrMatches = dateInfo.trim().match(regexString);
    console.log(arrMatches);
willwade
  • 1,998
  • 2
  • 16
  • 22

2 Answers2

1

You need to remove the single quotes from the regexString to make it a regex literal:

 var dateInfo = `       This project was

                created on 09/02/2016

                     and last updated 10 days ago.`; 
var regexString = /This project was\s+created on ([0-9]{2})\/([0-9]{2})\/([0-9]{4})\s+and last updated ([0-9]+) ([a-zA-Z]+)/i;
var arrMatches = dateInfo.trim().match(regexString);
console.log(arrMatches);

No need for m modifier.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
0

I think that break lines (EOL chars) in string dateInfo broken the regular expression.