Extend regular expressions for non-strings

Very simple:

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].match(/[02468]/g) would give the result [0, 2, 4, 6, 8]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].match(/[02468]/) would give the result [0]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].match(/[345]+/g) would give the result [345]

1 Like

Wouldn't this only be useful for arrays whose items were entirely toString-able?

1 Like

Maybe. But as I understand, operations with strings are costly in the means of performance, so FAST means of working with arrays while using the syntax of regular expressions would be nice!

Also! Not only arrays! Why not this?

123456.match(/[024]/g) returns 24
123456.match(/[024]/) returns 2