当前位置:网站首页>One problem encountered:
One problem encountered:
2022-07-24 13:42:00 【Green ear~】
use js Process the contained string into an array containing these numbers ?
answer :
One 、 Use regular : for example
var str ="d567unt7jk80o9hkghftjs123ldka78sdassdfd653";
str.match(/\d+/g);//["567", "7", "80", "9", "123", "78", "653"]
Two 、 The other is not regular , Can you write it down , For guidance
function test(str){
var ret = [];
var isNum = false;
for(var i = 0, iLen = str.length; i < iLen; i++){
var charCode = str.charCodeAt(i);
if(charCode >= 48 && charCode <= 57){
if(isNum){
ret[ret.length - 1] += str[i];
}else{
ret.push(str[i]);
}
isNum = true;
}else{
isNum = false;
}
}
return ret;
}
test('d567unt7jk80o9hkghftjs123ldka78sdassdfd653');
边栏推荐
- 第六章 总线
- Go redis pipeline application
- 网络安全——WAR后门部署
- Network security - file upload content check bypass
- Interview question 01.02. determine whether it is character rearrangement
- Browser type judgment
- HCIP第十三天
- R语言ggpubr包的ggarrange函数将多幅图像组合起来、annotate_figure为组合图像添加注释、注解、标注信息、使用left参数在可视化图像左侧添加注解信息(字体颜色、旋转角度等)
- Kunyu(坤舆) 安装 详解
- The scroll bar in unity ugui is not displayed from the top when launching the interface in the game
猜你喜欢

为什么函数式接口 Comparator 中有 “两个抽象方法”?

Network security - use exchange SSRF vulnerabilities in combination with NTLM trunking for penetration testing

Swarm intelligence collaborative obstacle avoidance method inspired by brain attention mechanism

网络安全——报错注入

Thread multithreading

Kunyu(坤舆) 安装 详解

CSDN garbage has no bottom line!

Why are there "two abstract methods" in the functional interface comparator?

网络安全——使用Evil Maid物理访问安全漏洞进行渗透

网络安全——中间人攻击渗透测试
随机推荐
Queue (stack)
Thread multithreading
2022年全国职业院校技能大赛赛项比赛时间、承办校信息统计表(第二批)
网络安全——使用Exchange SSRF 漏洞结合NTLM中继进行渗透测试
Selenium environment configuration and eight elements positioning
Flex layout
网络安全——WAR后门部署
Network security -- man in the middle attack penetration test
Kunyu(坤舆) 安装 详解
CSDN垃圾的没有底线!
Go redis pipeline application
Explain flex layout in detail
position: -webkit-sticky; /* for Safari */ position: sticky;
汉字风格迁移篇---用于汉字多字体生成的多样性正则化StarGAN
Cmake basic grammar (1)
支持鹏程系列开源大模型应用生态演化的可持续学习能力探索
网络安全——文件上传黑名单绕过
R语言使用epiDisplay包的tableStack函数制作统计汇总表格(基于目标变量分组的描述性统计、假设检验等)、设置by参数为目标变量、设置percent参数配置是否显示百分比信息
从云原生到智能化,深度解读行业首个「视频直播技术最佳实践图谱」
基于图正则化的贝叶斯宽度学习系统