I need to extract all MP3 titles from a fuzzy list in a list.
With Python this works for me fine:
import re
for i in re.compile('mmc.+?mp3').findall(open("tracklist.txt").read()): print i
How can I do that in Ruby?
f = File.new("tracklist.txt", "r")
s = f.read
s.scan(/mmc.+?mp3/) do |track|
puts track
end
What this code does is open the file for reading and reads the contents as a string into variable s
. Then the string is scanned for the regular expression /mmc.+?mp3/
(String#scan
collects an array of all matches), and prints each one it finds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With