0

a propper diagnosis in my data can have the format:

"F10"
"F10.1"
"F32.124"

I try to extract these correct format within a for loop:

Diagnosen[i] <- str_extract(Diagnosen[i], pattern = "F[:digit:]{2}[\\.[:digit:]{1,3}]?") 

But the results are cut off after the point. Exp:

"F10." 

what is not a correct format and lost information.

My pattern shall mean: Find the string beginning with an F and 2 digits. Optional is a point with one to three digits.

Please help me. Best Sebastian

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
S O
  • 11
  • 2
  • Replace bracket expression with a grouping construct, `"F[:digit:]{2}(\\.[:digit:]{1,3})?"` – Wiktor Stribiżew Sep 02 '20 at 09:57
  • you can try `grep("^F\\d{2}(\\.\\d{1,3})?$", diagnosen, value=TRUE)` – Cath Sep 02 '20 at 09:57
  • Thank you very much. Wiktors solution worked for me. I didn't have to change the rest of my thinking, what was quite good for me. Thank you, Cath aswell. – S O Sep 03 '20 at 11:12

0 Answers0