var str = `Then I should 'create' 'adhoc payments' on '01' working day of pay period '04' of 'Current' Fiscal` var spilitArr = str.split(" "); var filterArr = spilitArr.filter(e=>e.includes("'")); // s.match(/'([^']+)'/)[1]; console.log(spilitArr, 'spilitArr') console.log(filterArr, 'filterArr') console.log(`expected array:' , ['create' 'adhoc payments', '01', '04', 'Current']`)Intenté de varias maneras, ¿alguien puede ayudarme?
Estabas ladrando al árbol correcto con tu intento RegExp; un patrón como /(?<=\W').+?(?='\W)/g probablemente lo llevará a donde necesita estar para cumplir con su requisito:
var str = `Then I should 'create' 'adhoc payments' on '01' working day of pay period '04' of 'Current' Fiscal` const pattern = /(?<=\W').+?(?='\W)/g; const matches = str.match(pattern); console.log(matches); var str = `Then I should 'create' 'adhoc payments' on '01' working day of pay period '04' of 'Current' Fiscal` const pattern = /'(.*?)'/g; const matches = str.match(pattern).map(e => e.substring(1,e.length-1)) console.log(matches); var str = `Then I should 'create' 'adhoc payments' on '01' working day of pay period '04' of 'Current' Fiscal`; let res = []; for( let a=0; a<str.length; a++ ){ const sqOpen = str.indexOf("'", a); const sqClose =( sqOpen !== -1 )? str.indexOf("'", sqOpen+1):-1; if( sqClose !== -1 ){ a = sqClose + 1; res.push( str.slice(sqOpen+1, sqClose ) ); }else{ break; } } console.log(res);