javascript - A small question about regular expressions, please solve it
世界只因有你
世界只因有你 2017-06-26 10:54:22
0
1
666
  1. Now I have a requirement, for example, let a = 'asdadaasd.jpg'||'Chinese.png';
    2. Now I need to intercept .jpg||.png|| .gif||.jpeg The first 8 digits are '...'.png

let a = 'asdasdqweqweqwadsdasd.png';
let reg = /正则/;
      let strSub =>(filename){
              
            xxx
              return filename
    }
    // 输出的 filename  为 asdasdqweq....png;
世界只因有你
世界只因有你

reply all(1)
我想大声告诉你

Practice your hands, it is not recommended to use regular rules

Regular method---code

let testStr='asdasdqweqweqwadsdasd.png';
let reg=/(\w{8})\S+([.](?:png|jpeg|gif|jpg))/;
let newStr=testStr.replace(reg,function(match,p1,p2,offset,string){
      return p1+p2;
    });
console.log(newStr)

This is the best way to actually intercept strings code:

let testStr='asdasdqweqweqwadsdasd.png';
let index=testStr.lastIndexOf(".");
let newStr=testStr.substr(0,8)+testStr.substr(index,testStr.length-index);
console.log(newStr)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template