更新时间:2021-12-22 05:19:22
f = File.new("tracklist.txt", "r")
s = f.read
s.scan(/mmc.+?mp3/) do |track|
puts track
end
这段代码的作用是打开文件进行读取并将内容作为字符串读入变量s
.然后对字符串扫描正则表达式 /mmc.+?mp3/
(String#scan
收集所有匹配的数组),并打印它找到的每一个.
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.