preg_match_all JS等价? [英] preg_match_all JS equivalent?

查看:101
本文介绍了preg_match_all JS等价?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Javascript中是否有相当于PHP的preg_match_all?如果没有,那么将正则表达式的所有匹配项放入数组的最佳方法是什么?我愿意使用任何JS库来使它更容易。

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 any JS library to make it easier.

推荐答案

你可以使用匹配使用全局修饰符:

You can use match with the global modifier:

>>> '1 2 3 4'.match(/\d/g);
["1", "2", "3", "4"]

这篇关于preg_match_all JS等价?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆