Open GenweiWu opened 5 years ago
1、string.repalceAll ?
"/aa/bb/cc".replace(new RegExp("/[^/]+","gm"),"")
""
2、string.replaceFirst ?
"/aa/bb/cc".replace(new RegExp("/[^/]+","m"),"")
"/bb/cc"
"/11/22/33".replace(new RegExp("/[^/]+","m"),"")
"/22/33"
replace默认匹配第一个,g表示匹配所有,m表示进行多行匹配
//1
'/a/b/c'.match('/[^/]+/[^/]+/[^/]+')
//2
'/a/b/c'.match('(/[^/]+)(/[^/]+)(/[^/]+)')
//3
'/a/b/c'.match('(?<group1>/[^/]+)(?<group2>/[^/]+)(?<group3>/[^/]+)')
0,1,2
可以理解成group0,group1,group2?<name>
来得到命名的group匹配
资料
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp