Return true/false for a matched/not matched regex

The more appropriate function here might be RegExp.test, which explicitly gives you true or false.

console.log(/lolcakes/.test("some string"));
// Output: false

console.log(/lolcakes/.test("some lolcakes"));
// Output: true

Use a double logical NOT operator.

return !!removedTL;

This will convert to true/false depending on if matches are found.

No matches gives you null, which is converted to false.

One or more matches gives you an Array, which is converted to true.


As an alternative, you can use .test() instead of .match().

/^(\d\d) - (\?\?|10|0\d):(\?\?|[0-5]\d):(\?\?|[0-5]\d) - (.*)/.test( myS );

...which gives you a boolean result directly.


The match method will return null if there is no match.