exec() :RegExpObject.exec(string) match() :stringObject.match(string)stringObject.match(regexp)知识点:
var text = "mom and dad and baby";var pattern = /(mom and )?(dad and )?baby/;var matches = text.match(pattern);//pattern.exec(text);console.log(matches.index);console.log(matches.input);console.log(matches[0]);console.log(matches[1]);console.log(matches[2]);对 match() 的测试结果截图:

对 exec() 的测试代码:
var text = "mom and dad and baby";var pattern = /(mom and )?(dad and )?baby/;var matches = pattern.exec(text);//text.match(pattern);console.log(matches.index);console.log(matches.input);console.log(matches[0]);console.log(matches[1]);console.log(matches[2]);对 exec() 的测试结果截图:

String 对象方法
| 方法 | 描述 |
| exec | 检索字符串中指定的值。返回找到的值,并确定其位置 |
| test | 检索字符串中指定的值。返回 true 或 false。 |
| 方法 | 描述 |
| match() | 找到一个或多个正则表达式的匹配。 |
| replace() | 替换与正则表达式匹配的子串。 |
| search() | 检索与正则表达式相匹配的值。 |