
利用正则判断是否以Welcome开头
let str = "Welcome to the web site building tutorial!";
let regex = /^Welcome/;
if (regex.test(str)) {
console.log("判断当前字符串是以web开头!");
} else {
console.log("判断当前字符串不以web开头!");
}
//输出结果:判断当前字符串是以web开头!
利用正则输出字符串部分内容
let str = "Welcome to the web site building tutorial!";
let regex = /^Welcome(.*)/;
let result = regex.exec(str);
if (result != null) {
console.log('输出:', result[0]); // 输出: Welcome to the web site building tutorial!
console.log('输出:', result[1]); // 输出: to the web site building tutorial!
}
上面是“javascript正则表达式实现字符串匹配输出”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_4502.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

帝国cms JS登陆状态模板中调用显示会员收到的短
Meta ARE:Meta出品,面向AI Agents的动态模拟研究与评估平台
Bobby APP
布雷克影院:最新电影、热门电视剧、经典动漫和综艺节目
GLM-4-32B:智谱新一代开源基座大模型,支持HTML/CSS/JS/SVG等语言