get first matched in regular expression javascript code example Example: javascript regex for firstname var nameRegex = /^[a-zA-Z\-]+$/;