re = /(?i)(?:\w+\W+){0,9}?(?=.*(?:plot).*|.*(?:over).*)(?:\w+\W+){0,9}?(?=Charlie|Muir|Charlie Muir)\K(?:(?:Charlie|Muir|Charlie Muir)\s+)+/m
str = '
cHarlie muir charlie charlie was over the moon the the the the the tge the the the
-the the the the the the the the the the the the the the the the the-
over was the the the moon parker parker charlie muir charlie
-the the the the the the the the the the the the the the the the the-
Charlie muir charlie was near the plot
-the the the the the the the the the the the the the the the the the-
ChArlie was far away from the plot was far away from the
-the the the the the the the the the the the the the the the the the-
the plot was far away from CharLie
-the the the the the the the the the the the the the the the the the-
the plot was far away from CharLie muir charlie
-the the the the the the the the the the the the the the the the the-
the over was far away from CHarlie muir
-the the the the the the the the the the the the the the the the the-
Mr cHARLIE was bowled over test was bowled after the ball
-the the the the the the the the the the the the the the the the the-
over the test was bowled muIR
-the the the the the the the the the the the the the the the the the-
the plot the ball the slot it will plot the test was bowled MuiR
-the the the the the the the the the the the the the the the the the-
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html