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

219
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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