regex - JavaScript text between double quotes -


i text between double quotes using javascript. found online title.match(/".*?"/); thing have text between double quotes there no quotes. saying receive strings like: neque porro quisquam est qui dolorem ipsum , strings like: neque "porro quisquam est" qui dolorem ipsum. thing is, when have text containing double quotes want retrieve text between them when aren't present, i'd whole text. have observered string.indexof("\"") not work , don't know how approach problem. thanks.

try:

var str1 = 'neque porro quisquam est qui dolorem ipsum'; var str2 = 'neque "porro quisquam est" qui dolorem ipsum';  function extracttext( str ){   var ret = "";    if ( /"/.test( str ) ){     ret = str.match( /"(.*?)"/ )[1];   } else {     ret = str;   }    return ret; } 

then

extracttext( str1 ); //neque porro quisquam est qui dolorem ipsum extracttext( str2 ); //porro quisquam est 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -