如何使用正则表达式函数RegExp
1个回答
展开全部
假设你问的是javascript
这个正则找到所有以小写字母组成的单词
const regex = new RegExp('\b[a-z]+\b', 'g');
const str = `Hello How are you`;
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}`);
});
}
这个正则找到所有以小写字母组成的单词
const regex = new RegExp('\b[a-z]+\b', 'g');
const str = `Hello How are you`;
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}`);
});
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询