JavaScript regular expression in Actions All In One
JavaScript 正则表达式实战
demos
在字符串中匹配多组数据
const str = 'lines[0][config][options][343]';
const reg = /\[([0-9]+|[a-z]+|[A-Z]+)\]/g;
const groups = [];
str.replaceAll(reg, group => {
let value = group.replace(`[`, ``).replace(`]`, ``)
groups.push(value)
return ''
});
console.log(`groups =`, groups);
// ['0', 'config', 'options', '343']
// one more thing ✅
const arr = groups.map(item => isNaN(item) ? item : parseInt(item))
console.log(`arr =`, arr);
// [0, 'config', 'options', 343]
https://stackoverflow.com/a/76953550/5934465
(? 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
refs
https://stackoverflow.com/questions/76952844/replace-words-in-string-with-values-of-string-array
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 ?️,侵权必究⚠️!
- JavaScript expression Actions regular Alljavascript expression actions regular expression javascript regular special regular-expression-matching expression regular regular-expression-matching expression leetcode expression working regular python expression learning regular new python_regular expression regular基础 atcoder regular contest express expression regular linux shell