fork download
  1. library(stringr)
  2. x <- c("PIA+1+TC_5504_00_312010_0050+50103 AB346 type 5334",
  3. "PIA+1+TC_3444_00_312010_0133+0140",
  4. "PIA+1+DRW/50488665600/01/000:DW",
  5. "PIA+1+TC_5635_00_312019_2644+LoremIpsum",
  6. "PIA+1+TC_5635_00_312010_0040+63503 AB346 type 5334",
  7. "PIA+1+TC_5635_00_312018_0223+DolorSit",
  8. "PIA+1+TC_5635_00_312019_2644+DolorSit")
  9. str_extract(x, "(?<=^PIA\\+\\d\\+)(?!.*(?:LoremIpsum|DolorSit)).*$")
Success #stdin #stdout 0.29s 42348KB
stdin
Standard input is empty
stdout
[1] "TC_5504_00_312010_0050+50103 AB346 type 5334"
[2] "TC_3444_00_312010_0133+0140"                 
[3] "DRW/50488665600/01/000:DW"                   
[4] NA                                            
[5] "TC_5635_00_312010_0040+63503 AB346 type 5334"
[6] NA                                            
[7] NA