I want to do something like this in Ruby
I have a text like this
some_random_text unit 1 some_random_text chap 3 some_random_text
Now I want to extract
some_random_text, 'unit 1', some_random_text, 'chap 3'
For this I use an expression like this
my_string.split(/(unit[1-9 ]+|chap[1-9 ]+)/)
I repeat the pattern [1-9 ]+ for both 'unit' and 'chap' because if I group like
/((unit|chap)[1-9 ]+)/
It returns
some_random_text, 'unit', 'unit 1', some_random_text, 'chap', 'chap 3'
which has extra elements I don't need.
How do I do the grouping I need?