情况就是这样:我想找到与正则表达式匹配的元素......
targetText ="SomeT1extSomeT2extSomeT3extSomeT4extSomeT5extSomeT6ext"
我在这样的javascript中使用正则表达式
reg = new RegExp(/e(.*?)e/g);   
var result = reg.exec(targetText);
而且我只获得第一个,但不是后续....我只能获得T1,但不能获得T2,T3 ......
cha*_*aos 68
var reg = /e(.*?)e/g;
var result;
while((result = reg.exec(targetText)) !== null) {
    doSomethingWith(result);
}
bit*_*ess 15
三种方法取决于你想用它做什么:
遍历每场比赛: .match
targetText.match(/e(.*?)e/g).forEach((element) => {
   // Do something with each element
});
循环并在飞行中替换每个匹配: .replace
const newTargetText = targetText.replace(/e(.*?)e/g, (match, $1) => {
  // Return the replacement leveraging the parameters.
});
循环并做一些事情: .exec
const regex = /e(.*?)e/g;  // Must be declared outside the while expression, 
                           // and must include the global "g" flag.
let result;
while(result = regex.exec(targetText)) {
  // Do something with result[0].
} 
tva*_*son 11
尝试在字符串而不是exec ()上使用match(),尽管你也可以使用exec循环.比赛应该一次性给你所有的比赛.我想你也可以省略全局说明符.
reg = new RegExp(/e(.*?)e/);   
var matches = targetText.match(reg);