I run this regex .match():
var pattern = /property="og:description"\scontent="(.+?)"/;
var matches = data.match(pattern);
if (matches[1]) {
var = description = matches[1];
}
But occasionally, I get this error:
Uncaught TypeError: matches is null
What can I do to check if matches[1] is not empty?
What I've tried so far
I tried this:
if (matches && matches[1]) {
And
if (matches.length && matches[1].length) {
And
if (matches[1] != null) {
And
if (matches[1] != undefined && matches[1] != null) {
Still getting this error occasionally. Clearly I'm missing something.