用正则截取、判断文件类型(持续更新)

1、截取两个字符串之间的内容:

let str = "aaabbbccc";
let result = str.match(/aaa(\S*)ccc/)[1]; // bbb

2、截取某个字符串前面的内容:

let str = "aaabbbccc";
let result = str.match(/(\S*)bbb/)[1]; // aaa

3、截取某个字符串后面的内容:

let str = "aaabbbccc";
let result = str.match(/aaa(\S*)/)[1]; // bbbccc

4、判断是否是某种类型的文件:

const reg = RegExp(/(?:png|jpg|jpeg|JPG|PNG|JPEG)$/)
let result = reg.test('test.png'); // true
let result = reg.test('test.html'); // false