Here are three ways that could be done.
str = "%Hello% dear %Cust Name% %your order %Order Nbr% was %lost%"
1. Use String#split
r = /
(?<= # begin positive lookbehind
\A # match beginning of string
| # or
[ ] # match a space
) # end positive lookbehind
(?=%) # positive lookahead asserts next char is '%'
| # or
(?<=%) # positive lookbehind asserts previous char is '%'
(?= # begin a positive lookahead
[ ] # match a space
| # or
\z # match end of string
) # end positive lookahead
/x # free-spacing regex definition mode
str.split r
#=> ["%Hello%", " dear ", "%Cust Name%", " ", "%your%", " order ",
# "%Order Nbr%", " was ", "%lost%"]
2. Use String#scan
r = /
%[^%]*% # match '%', 0+ chars other than '%', '%'
| # or
(?: # begin non-capture group#
(?<=\A) # positive lookbehind asserts at beginning of string
| # or
(?<=%) # positive lookbehind asserts previous char is '%'
(?=[ ]) # positive lookahead asserts next char is a space
) # end non-capture group
[^%]* # match 0+ chars other than '%'
(?= # begin positive lookahead
\z # match end of string
| # or
(?<=[ ]) # assert previous char is a space
% # match '%'
) # end positive lookahead
/x # free-spacing regex definition mode
str.scan r
#=> ["%Hello%", " dear ", "%Cust Name%", " ", "%your%", " order ",
# "%Order Nbr%", " was ", "%lost%"]
3. Use Enumerable#slice_when
str.each_char.slice_when { |a,b|
(a == ' ') & (b == '%') || (a == '%') & (b == ' ') }.map(&:join)
#=> ["%Hello%", " dear ", "%Cust Name%", " ", "%your%", " order ",
# "%Order Nbr%", " was ", "%lost%"]