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

163
Views
How create regexp for reapeted pattern?

In string available only 3 parameters : C1 - number is only 0 or 1 R1 - number is only 0 or 1 A

String Example "C1-R1-C0-C0-A-R0-R1-R1-A-C1"

Smth like this /[CRA]\d-/gi only for each with separetor

OR better use split and map methods?

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

0

If you are looking for a regular expression, something like this should work:

/^([CR][01]|A)(-([CR][01]|A))*$/

Essentially, we match a valid "parameter" as well as any number of "-parameter" after it. In context:

const string1 = 'C1-R1-C0-C0-A-R0-R1-R1-A-C1';
const string2 = 'invalid';

const testString = (string) => {
  return /^([CR][01]|A)(-([CR][01]|A))*$/.test(string);
};

console.log(testString(string1));
console.log(testString(string2));

Output:

true
false
about 4 years ago · Juan Pablo Isaza Report

0

Use split and then filter with the regexp.

let string = "C1-R1-C0-C0-A-R0-R1-R1-A-C1";
let result = string.split('-').filter(el => /^([CR][01]|A)$/.test(el));
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!