JavaScript text between double quotes

后端 未结 4 1720
刺人心
刺人心 2020-11-27 07:50

I would like to get the text between double quotes using JavaScript. I found online something like title.match(/\".*?\"/); but the thing is that sometimes I hav

4条回答
  •  伪装坚强ぢ
    2020-11-27 08:44

    split() function can be used get value in double quote

    let str1 = 'Neque "porro quisquam est" qui dolorem ipsum';
    let str2 = 'Neque porro quisquam est qui dolorem ipsum';
    
    function findFirstOccurance(str){
      const matches = str.split('"');
      return matches[1] ? matches[1] : str;
    }
    
    
    console.log(findFirstOccurance(str1));
    console.log(findFirstOccurance(str2)); 

提交回复
热议问题