Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda