const regex = new RegExp('.*斗地主', 'gm')
const str = `听好听的歌
我想听蜻蜓fm郭德纲的相声
我要听蜻蜓fm郭德纲的相声等等等等
蜻蜓的是的是的
听周杰伦的歌
蜻蜓fm于谦的相声
蜻蜓fm的于谦的相声
想听skds的草根创业最好的项目
想听刘德华的歌
我想听于放的相声的地点的电视
想听好听的音乐
想听铁齿铜牙纪晓岚
我想听中国之声
要听圣诞节
听蜻蜓fm
我想听相声
好听的歌
听广播电台
周杰伦的菊花台
听fm
听六千的相
听加快时间打开手机端
听有声书
听音乐
听蜻蜓fm收银员
听歌曲
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions