/ Published in: Ruby

This regular expression used in Ruby will extract the characters between single or multi-character delimiters. It helps when you have strange delimiters such as \":delimeter1: text I want to grab goes here :delimiter2:\"
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#Example row of data: 11/10/2010:Location: Home :Gender: M :Comment: I just wanted to say I had a great time at the party! :Email: [email protected] file = File.new("data.dlm", "r") File.open('output.txt', 'w') do |f1| while (line = file.gets) sub_string = line.scan(/:Comment:([^<>]*):Email:/imu).flatten f1.puts sub_string end end file.close
Comments
