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

124
Visualizações
Requires regex to compare last digit in string

Requires regex to compare last digit in string.

// For example: 
const reg = RegExp("anythink...5") // expression to check that the last number is 5
reg.test("2fae71c8-a657-41b7-8d8c-3d4da10285fc") => true
reg.test("2fae71c8-fc5") => true
reg.test("2364872368745") => true
reg.test("87415B11-7143-4E5B-9B25-6117571DFEC8") => false

Please help me find a solution.

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

0

You can use

/5(?=\D*$)/
/5(?!\D*\d)/

See the JavaScript demo:

const reg = /5(?=\D*$)/
console.log(reg.test("2fae71c8-a657-41b7-8d8c-3d4da10285fc")) // => true
console.log(reg.test("2fae71c8-fc5")) //=> true
console.log(reg.test("2364872368745")) //=> true
console.log(reg.test("87415B11-7143-4E5B-9B25-6117571DFEC8"))// => false

The 5(?=\D*$) regex matches

  • 5 - a 5 digit char
  • (?=\D*$) - a positive lookahead that requires zero or more non-digit chars till end of string
  • (?!\D*\d) - a negative lookahead that fails the match if there is a digit after 5 and any zero or more non-digit chars.
about 4 years ago · Juan Pablo Isaza Relatório

0

Use regexr.com to construct and check your Regular Expressions. You can even add multiple tests to see if it works for you in a glance.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can match 5 optionally followed by any char except a digit or a newline using:

5[^\d\n]*$

You might also use \D* to match any char except a digit, but note that it could also match a newline.

See a regex demo.

const reg = /5[^\d\n]*$/; // expression to check that the last number is 5
console.log(reg.test("2fae71c8-a657-41b7-8d8c-3d4da10285fc")); // => true
console.log(reg.test("2fae71c8-fc5")); // => true
console.log(reg.test("2364872368745")); // => true
console.log(reg.test("87415B11-7143-4E5B-9B25-6117571DFEC8")); // => false

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