0

I have this string

"1 36,8 stc smear" 

This means that the first smear was made from inpatient that had temperature 36,8

And I would like to get only the temperature

36,8

I used this

str_extract("1 36,8 stc smear", "(\\d)+(?= stc)")

But output was

8

Is it possible to get all the digits with "," to get output 36,8

onhalu
  • 735
  • 1
  • 5
  • 17
  • 1
    I think you are looking for `\\d+(?:,\\d+)?(?= stc)` – The fourth bird Feb 01 '21 at 13:48
  • @JvdV I don't think that a patient with a negative temperature reading is going to be getting seen by a doctor :0 – MonkeyZeus Feb 01 '21 at 13:51
  • @Thefourthbird Thank you - It works. Could you, please, provide me an explanation of your regex? – onhalu Feb 01 '21 at 13:54
  • 1
    @onhalu It matches 1 or more digits `\\d+` and then optionally matches a comma and again 1 or more digits using `(?:,\\d+)?` Note that you don't need the capture group around the number if you want a match only. – The fourth bird Feb 01 '21 at 13:57

0 Answers0