我有一个名为skip.txt
的文件,其中包含以下信息:
stackoverflow.com
github.com
www.sa-k.net
yoursearch.me
search1.speedbit.com
duckfm.net
search.clearch.org
webcache.googleusercontent.com
我还有一个名为information.txt
的文件,其中包含以下信息:
http://search.clearch.org/?a=web&q=Viewcat_h.php%3Fidcategory%3D%20%3Cstrong%3ESite%3C%2Fstrong%3E%20.pl%20
https://moodle.org/mod/forum/discuss.php?d=246409
http://webcache.googleusercontent.com/search?q=cache:oqPwN7FtDWgJ
http://www.aquariumist.com.ua/spr.php?id=7
http://search.clearch.org/?a%3Dweb%26q%3DViewcat_h.php%253Fidcategory%253D%2520%253Cstrong%253ESite%253C%252Fstrong%253E%2520.pl%2520%2Binurl:viewCat_h.php?idCategory%3D&hl=en&gbv=1&ct=clnk
http://www.astbury.leeds.ac.uk/research/spr.php
http://www.media4play.li/s/spr+php+id.html
http://v.virscan.org/SPR/PHP.ID.html
http://search.clearch.org/?a=images&q=Viewcat_h.php%3Fidcategory%3D+
http://search.clearch.org/?a=web&q=Inurl%20Viewcat_h.php%3Fidcategory%3D%20Site%20Clinsp=%3Fpvaid%3D97f2b2aa136c4af0936453a19d9ab1b2%26fcoid%3D302363
http://webcache.googleusercontent.com/search?q=cache:5qNE1JBqUeIJ
http://search.clearch.org/?a%3Dweb%26q%3DInurl%2520Viewcat_h.php%253Fidcategory%253D%2520Site%2520Cl%26insp%3D%253Fpvaid%253D97f2b2aa136c4af0936453a19d9ab1b2%2526fcoid%253D302363%2Binurl:viewCat_h.php?idCategory%3D&hl=en&gbv=1&ct=clnk
我想要一种方法来获取此信息并移动到next
URL,是否有一种方法可以从skip.txt
文件中读取,如果information.txt
文件包含skip.txt
文件中的任何内容,则移动到文件中的下一个URL?
预期输出:
http://www.astbury.leeds.ac.uk/research/spr.php
http://www.media4play.li/s/spr+php+id.html
http://v.virscan.org/SPR/PHP.ID.html
https://moodle.org/mod/forum/discuss.php?d=246409
http://www.aquariumist.com.ua/spr.php?id=7
我做了一些研究,发现了grep
函数,但这需要一个复杂的正则表达式,我不是很擅长。因此,如果您可以帮助我找到一种跳过skip.txt
中的信息的方法,或者帮助我使用正则表达式,那就太好了!提前谢谢你。
1条答案
按热度按时间x6h2sr281#
假设将跳过文件读入变量
skip
,将信息文件读入变量info_file
。然后,.map(&:strip)
(您可以将其视为.map { |s| s.strip }
)使用String#strip删除skip.split("\n")
生成的数组元素周围的任何空格。这可能不是必要的,但这是一种预防措施,不会造成伤害。接下来我们定义一个正则表达式。
最后,使用Array#reject方法删除
info.arr
中与这个“regex”匹配的元素: