I have been struggling trying to get an efficient strategy to solve this.
Given the following string:
strings <- c("PMLR01TR060055PB01", "PMLR01BE080001PD01")
How can I remove the fixed start ("PMLR01"
) and the variable ending ("PB01"
or "PD01"
), to have
TR060055
and BE080001
.
I have a huge number of entries (10000+) and would like to have a efficient strategy to select this for all. Ideally, I would need some strategy to remove everything before the TR
or BE
, and everything after the numbers of the substring I would like to keep. Like this I would cover all possible angles.
I tried a very naive approach:
substr("PMLR01TR060055PB01", 7, 14)
But if by any chance one of the strings doesn't match exactly the number of characters, I will have a problem.