Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
How to retrieve single quote words form sentence in javascript?

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.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

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);

about 4 years ago · Juan Pablo Isaza Report

0

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);

about 4 years ago · Juan Pablo Isaza Report

0

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);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!