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

123
Views
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 answers
Answer question

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 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!