正则表达式分组(Grouping)

 

一 捕获型

 

(x)  匹配 x ,并且捕获匹配项

 

const regExp = /(\w+)\s+(\d+)/;
const str = 'Android 8';
str.replace(regExp,'$1,KFC')

 

 

二 非捕获型

 

(?:x)  匹配 x ,但不捕获匹配项

 

const regExp = /(?:\w+)\s+(\d+)/;
const str = 'Android 8';
str.replace(regExp,'KFC')

 

 

posted on 2019-11-14 21:59  沙滩海风  阅读(333)  评论(0编辑  收藏  举报

导航