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

154
Visualizações
Regex Always False multi Pattern

I am facing a weird issue with Regex. My expression working fine in https://regexr.com/3cr6f But when i use the same expression in my code then it start failing.

This is my Expression:

^([a-zA-Z]+\\)+(Documents){1}\\{1}((CT([A-Za-z]){0,2})|(FE)|(FF))$

I want to test this expression on my typescript string:

 var case1='User\Folders\MyDocuments\CTTV';
 var case2='User\Folders\MyDocuments\FE';
 var case3='User\Folders\MyDocuments\FF';

But it always return me null.

var regex = new RegExp(/^([a-zA-Z]+\\)+(Documents){1}\\{1}((CT([A-Za-z]){0,2})|(FE)|(FF))$/);
regex.test(case1); //false

Might be someone else also faced such issue in Javascript typescript.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

As pointed out by one of the comments, the test strings are MyDocuments but your regex has Documents. If you adjust your regex to this:

^([a-zA-Z]+\\)+(MyDocuments){1}\\{1}((CT([A-Za-z]){0,2})|(FE)|(FF))$

It works fine

https://regex101.com/r/xoGaue/1

about 4 years ago · Juan Pablo Isaza Relatório

0

So the reason why it does not work at the moment is that you are trying to match the string myDocuments to Documents.

To fix your regex I would add a partial match for regex by adding .*? this will match any possible characters.

^([a-zA-Z]+\\)+(.*?Documents.*?){1}\\{1}((CT([A-Za-z]){0,2})|(FE)|(FF))

but I would change your regex all together:

if you do not care about the document folder then I would suggest:

^(.+)\\+((CT([A-Za-z]){0,2})|(FE)|(FF))$

else you can use:

^(.+)\\+(.*?Documents.*?){1}\\((CT([A-Za-z]){0,2})|(FE)|(FF))$

see here:

https://regex101.com/r/qd4Fjs/1

about 4 years ago · Juan Pablo Isaza Relatório

0

  1. add "My" to "Documents"
  2. use String.raw`` to escape backslash

Check it out": https://playcode.io/918676/

    let 
    case1=String.raw`User\Folders\MyDocuments\CTTV`,
    case2=String.raw`User\Folders\MyDocuments\FE`,
    case3=String.raw`User\Folders\MyDocuments\FF`,
    case4=String.raw`User\Folders\MyDocuments\False`

    let regex = new RegExp(/^([a-zA-Z]+\\)+(MyDocuments){1}\\{1}((CT([A-Za-z]){0,2})|(FE)|(FF))$/);
    
    console.log(
      regex.test(case1),
      regex.test(case2),
      regex.test(case3),
      regex.test(case4)
    )

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