I have the following string
string <- c(\'a - b - c - d\',
\'z - c - b\',
\'y\',
\'u - z\')
I would
try this (\w(?:\s+-\s+\w)?).*
. For the explanation of the regex look this https://regex101.com/r/BbfsNQ/2.
That regex will retrieve the first tuple if exists or just the first caracter if there's not a tuple. So, the data is get into a "capturing group". Then to display the captured groups, it depends on the used language but in pure regex that will be \1
to get the first group (\2
to get second etc...). Look at the part "Substitution" on the regex101 if you wan't a graphic example.