使用JavaScript匹配字符串中的多次出现?
要匹配字符串中的多次出现,请使用正则表达式。以下是代码-
示例
function checkMultipleOccurrences(sentence) {
var matchExpression = /(JavaScript?[^\s]+)|(typescript?[^\s]+)/g;
return sentence.match(matchExpression);
}
var sentence="This is my first JavaScript Program which is the subset
of typescript";
console.log(sentence);
console.log(checkMultipleOccurrences(sentence));要运行上述程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo70.js。
输出结果
这将产生以下输出-
PS C:\Users\Amit\JavaScript-code> node demo70.js This is my first JavaScript Program which is the subset of typescript [ 'JavaScript', 'typescript' ]
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短