Suppose I have the following strings to parse for use in R:
PIA+1+TC_5504_00_312010_0050+50103 AB346 type 5334
PIA+1+TC_3444_00_312010_0133+0140
PIA+1+DRW/50488665600/01/000:DW
PIA+1+TC_5635_00_312019_2644+LoremIpsum
PIA+1+TC_5635_00_312010_0040+63503 AB346 type 5334
PIA+1+TC_5635_00_312018_0223+DolorSit
PIA+1+TC_5635_00_312019_2644+DolorSit
In a nutshell, the logic is this:
- Capture everything after the positive lookbehind
(?<=^PIA\+\d{1}\+) - Do not capture where the string contains either
LoremIpsumorDolorSit
The desired output should look like this:
TC_5504_00_312010_0050+50103 AB346 type 5334
TC_3444_00_312010_0133+0140
DRW/50488665600/01/000:DW
TC_5635_00_312010_0040+63503 AB346 type 5334
This is where I got to thus far:
(?<=^PIA\+\d{1}\+)((?!.*LoremIpsum|DolorSit).)*$
I have deliberately not escaped according to R yet but will do so later.
But unfortunately it keeps the last digit of the capture into a new group. My experience in regex is limited and I am stuck how to capture the entire remaining string in a group. I am not bound to this approach and another logic could be, that whenever the last + is followed by a letter, it should exclude the capture but that would result in difficulties adding occasions with the PIA+1+DRW/50488665600/01/000:DW strings.
My samples are stored here regex101.com