How to loop all the elements that match the regex?

前端 未结 8 1553
囚心锁ツ
囚心锁ツ 2020-12-02 18:27

Here is the case: I want to find the elements which match the regex...

targetText = \"SomeT1extSomeT2extSomeT3extSomeT4extSomeT5extSomeT6ext\"

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 18:50

    Try using match() on the string instead of exec(), though you could loop with exec as well. Match should give you the all the matches at one go. I think you can omit the global specifier as well.

    reg = new RegExp(/e(.*?)e/);   
    var matches = targetText.match(reg);
    

提交回复
热议问题