Match a string with a regular expression in JavaScript

October 8, 2014

To find a match with a regular expression, use match on strings (returns an array of matches):

js
var s = "abc";
s.match(/c/); => ["c"]

or test on RegExp (returns true or false):

js
/c/.test(s); => true