I have these tests string :
abc optional def ghi
abc def ghi
that both match this regex
(.+) ((optional \s*)?def)\s+(.+)
https://regex101.com/r/0pZQEy/1
but I want to group optional with def whereas it groups optional with abc, I can't see how to fix this