Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda