for (var str = "math.sin() math.cos() math.Pi random.get() random.set() ", re = /(math|random)\.(\w+)[()]{2}/g, a = []; re.exec(str) != null;) a.push(RegExp.$2); alert(a);