const regex = /static.*/g;
const str = `src\main\webapp\static\ca7ecd95-aa95-4da8-b369-92b66b566958\icon.png`;
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}`);
});
雷雷
split('static')[1] 這樣的嗎? 還是必須用正規?
str.slice(str.search(/static/));
正規應該用 static.* 就可以,下面是參考代碼
'srcmainwebappstaticca7ecd95-aa95-4da8-b369-92b66b566958icon.png'.split('static')[1]
這個問題的亮點: