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']`)
Tried multiple ways, can any one help me.
You were kind of barking up the right tree with your RegExp attempt; a pattern like /(?<=\W').+?(?='\W)/g will probably get you to where you need to be to meet your requirement:
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);