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

108
Views
Regex string split with multiple conditions

(Javascript older version of Node.js)

Edit I have to clear up what I want.

I have multiple lines like these

var name1;

CONST    name2

   Let  nam;

leT     nam

  VAr n1  ;

My desired outputs are

name1

name2

nam

nam

n1

So I am trying codes like this.

/[^;]*/

But I need help because I have multiple patterns. Some may have semicolons/space/null after the variable names, I need to omit those.

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

0

use /(?<=(var\s+)|(let\s+)|(const\s+))(\w+)/gim

let data = `
var name1;

CONST    name2

   Let  nam;

leT     nam

  VAr n1  ;
`;
data = data.match(/(?<=(var\s+)|(let\s+)|(const\s+))(\w+)/gim);
console.log(data); // [ 'name1', 'name2', 'nam', 'nam', 'n1' ]

about 4 years ago · Juan Pablo Isaza Report

0

Use regexp = /name[1-9]+/g

let arr = ['var person;', 'CONST    name2', '   Let  nam;', '  VAr n1  ;'];
var result = [];
for(var s of arr) {
    var split_array = s.replace(/  +/g, ' ').trim().split(' ');
    result.push(split_array[1].replace(';', ''))
}
console.log(result);

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!