re = /(?<=filename="Myfile\.pdf")\s+((?:\S+\s)+\S+)=/
str = '--------------A5B0A8B4F69F8BD959B758D0
Content-Type: application/pdf;
name="Myfile.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="Myfile.pdf"
JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlL1hPYmplY3QvQ29sb3JT
ZWI0ODRmNDE1ZDE0YmIyZmU2YjAzZDMzNjU+PGU5MDFiZTMzY2FlOTY4ZDM2
NmFmOGNhOTUxNTE0Nzk0Pl0vSW5mbyAyMyAwIFIvU2l6ZSAyND4+CnN0YXJ0
eHJlZgoyMzg2NgolJUVPRgo=
--------------A5B0A8B4F69F8BD959B758D0--'
# 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