preg_match_all JS equivalent?

前端 未结 4 1572
孤独总比滥情好
孤独总比滥情好 2021-02-05 09:47

Is there an equivalent of PHP\'s preg_match_all in Javascript? If not, what would be the best way to get all matches of a regular expression into an array? I\'m willing to use a

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 09:58

    Use new RegExp().test()

    function preg_match_all(regex, str) {
      return new RegExp(regex,'g').test(str)
    }

提交回复
热议问题