从两个分隔符之间删除字符
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从两个分隔符之间删除字符相关的知识,希望对你有一定的参考价值。
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:\"
#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
以上是关于从两个分隔符之间删除字符的主要内容,如果未能解决你的问题,请参考以下文章