我无法使用 Lodash 成功将字符串与正则表达式匹配。
我会尝试以下代码示例:
regex = /foo/;
// ele.id might be undefined
_.result(ele.id, 'match(regex)');
_.invoke(ele.id, ['match'], [regex]);
_.invoke(ele.id, ['match'], ['regex']);
有人知道如何使用 Lodash 字符串匹配正则表达式参数吗?
最佳答案
为什么不使用 vanilla JS 呢?
var regex = /foo/;
var string = "foo";
console.log(regex.test(string))
关于javascript - 如何使用 Lodash 将字符串与正则表达式匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58104683/