regex problem in ruby, and for some reason, I need this in one line in gsub method of ruby
Suppose the input sample
string variable is multi line string like below
begin1 item abc item abc item
extra end1
begin2 item abc item abc extra end2
begin1 item abc item abc extra end1
The rule is to change all item
which inside block begin1
and end1
into love
, it may across multi lines
After replace, the output sample
should be
begin1 love abc love abc love
extra end1
begin2 item abc item abc extra end2
begin1 love abc love abc love end1
The solution is something like this
puts sample.gsub!(/(begin1.*)item*(.*end1)/m,'\1love\2')