What about this code?
doc.traverse do |x|
if x.text?
x.content = x.content.gsub(/(?<=[.!?])(?!\*)/, "#{$1}*")
end
end
The traverse
method does pretty much the same as search("*").each
. Then you check that the node is a Nokogiri::XML::Text
and, if so, change the content
as you wished.