Strip characters from between two delimiters

/ Published in: Ruby
Save to your folder(s)

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:\"

Copy this code and paste it in your HTML
  1. #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]
  3. file ="data.dlm", "r")
  4.'output.txt', 'w') do |f1| while (line = file.gets)
  5. sub_string = line.scan(/:Comment:([^<>]*):Email:/imu).flatten
  6. f1.puts sub_string
  7. end
  8. end
  9. file.close

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.