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

215
Views
Extracting filename with javascript

I'm trying to learn how to write a few rows of code in javascript on splitting a filename and extracting only certain characters.

For example I have a filename: "bk_is_great_2022119205974100_8Y.xlsx"

and I want to extract/display only 202211 from the filename.

var  Type = function getFourthPart (str){
     return str.split('_')][0,6];
}

How would I go about doing this? I've tried looking for answers but so far nothing that points toward what I'm looking for and this is all I've managed to create with my limited knowledge.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If you are trying to display only 5 letters of the date from the filename always, then you can use the below statement to extract only those parts.

a.split('_')[3].substring(0,6)
about 4 years ago · Juan Pablo Isaza Report

0

You might use a regex to match the first 3 occurrences of an underscore and right after that capture 6 digits in capture group 1.

^(?:[^\s_]*_){3}(\d{6})

In parts the pattern matches:

  • ^ Start of string
  • (?:[^\s_]*_){3} Repeat 3 times matching optional non whitespace chars except _ and then match _
  • (\d{6}) Capture group 1, match 6 digits

const s = "bk_is_great_2022119205974100_8Y.xlsx";
const regex = /^(?:[^\s_]*_){3}(\d{6})/;
const m = s.match(regex);

if (m) {
  console.log(m[1]);
}

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!