re = /[^\s$]*\$[^$]+\$[^\s$]*/m
str = '\'Slope fields are constructed by plotting tiny line segments at various points in the $xy$-plane. The slope of each line segment is given by the value of $f(x, y)$ at that corresponding run-on-sentence$()$followed-by-another$DHF$group point. These line segments collectively form a field of slopes, hence the name "slope field." and more some-$yz$-something else\''
# 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