I have a regex function that takes a string and matches any word followed by a comma and a year.
function getAuthorFromTitle(title) {
var regexForauthor = /(?<author>\w+(?=, \d+))/gs;
var resultRegEx = regexForauthor.exec(title);
var author = resultRegEx !== null ? resultRegEx.groups.author : "0000000000";
return author;
}
This works great for titles containing English characters, but if I have any Diacritics or Accents the script returns null.
console.log("This works", getAuthorFromTitle("Robert Bresson, 1951"));
console.log("This does not work", getAuthorFromTitle("Kornél Mundruczó, 2014"));
Any idea on how to match words that include Diacritics or Accents?
If you want to fiddle with the code please check out this Codepen: https://codepen.io/anything/pen/XWjwgea?editors=1011