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

126
Visualizações
Require.context regex issue

The require.context function that brings files based on the regex expression.

I want to add to starts with expression to these expressions so fetch that only starts with 1-**.js files. How can I do that?

 const folders = require.context("@/views", true, /^1-.*\.js$/, "lazy")

// 1-asd.js => true
// 2-asd.js => false
// 1-bsd.js => true

The paths that the regex engine receives look like this:

enter image description here

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

0

The input strings that the engine regex gets contain both the folder and file name parts. Thus, to make sure you match 1- at the start of the file name only, you need to match till the last slash:

/^(?:.*\/)?1-[^\/]*\.js$/

Or, if the / is always present in the paths, you can shorten the regex to

/^.*\/1-[^\/]*\.js$/
\/1-[^\/]*\.js$

Details:

  • ^ - start of string
  • (?:.*\/)? - an optional sequence of any zero or more chars other than line break chars as many as possible and then /
  • 1- - 1- string
  • [^\/]* - zero or more chars other than /
  • \.js$ - .js at the end of string.

See the regex demo

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