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

269
Visualizações
Extract blood pressure values from string

I have some strings containing blood pressure data, the numbers before the / indicate the higher/upper end of the blood pressure (systolic), and the numbers after the / indicate the lower end of the blood pressure (diastolic).

The strings are like this

let str1 = "170/80"; // Should Pass
let str2 = "90/60"; // Should Pass
let str3 = "140/90"; // Should Pass
let str4 = "should not/pass"; // Shouldn't Pass

I have a regex that tries to make sure that these strings indeed are blood pressure readings, i.e., making sure that the values are all numbers and in between them is a / but it doesn't seem to work (It's not matching even with the supposedly correct strings).

My regex is: ((\d)/(\d))

Can anyone tell me why it's not working? and what should be the correct regex for this?

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

0

The issue in your regex is that you're not escaping your slash \, but also you are matching single digits \d. In order to solve these problems, you may want a regex like this:

(\d+)\/(\d+)

Check the demo here.

about 4 years ago · Juan Pablo Isaza Relatório

0

As mentioned in the comments, you can use \d+ to match multiple digits. However, if your text can contain other numbers, you might want to use the more specific \d{1,3} to capture only values in the valid range for blood pressure. The complete regex would be ((\d{1,3})\/(\d{1,3}))

about 4 years ago · Juan Pablo Isaza Relatório

0

Escape the slash and use more than one digit

https://regex101.com/r/uC2w4h/1

Here with sanity tests to remove dates or other weird numbers. Change 45 to however low you want to test.

const str = `170/80  90/60 140/90 should not/pass on 11/12`
const bps = [...str.match(/(\d{2,3})\/(\d{2,3})/g)].filter(match => {
  const [syst,diast] = match.split("/")
  return +syst > 45 && diast > 45;
})

console.log(bps)

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