过滤文件或字符串中的内容 [英] filter something from file or string

查看:66
本文介绍了过滤文件或字符串中的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在处理一个问题,我必须扫描一个短文并打印出其中的所有IP地址。


假设我有一个文本存储在名为''test''的文件中,我写了一个小的perl程序,它读取文本的所有行并打印出任何ip地址:


打开文件,测试或者死!$ ;;


I''m dealing with a problem in which I have to scan through a short text and print out all ip addresses within it.

assume I have a text stored in a file named ''test'', and I write a small perl program which read all lines of the text and print out any ip address:

open FILE, "test" or die $!;

展开 | 选择 | Wrap | 行号

推荐答案

!;
!;
展开 | 选择 | Wrap | 行号


在regexp上尝试使用/ g修饰符逐步搜索。你必须稍微调整你的代码,但它不应该太糟糕。
Try the /g modifier on your regexp to progressively search. You''ll have to fiddle with your code a bit, but it shouldn''t be too bad.



试试/ g你的regexp上的修饰符可以逐步搜索。你必须稍微调整你的代码,但它不应该太糟糕。
Try the /g modifier on your regexp to progressively search. You''ll have to fiddle with your code a bit, but it shouldn''t be too bad.



错误,怎么回事? perl对我来说很新,虽然我说它就像php一样。有没有更好的方式来阅读整篇文章并拿起我们想要的东西?

err, how is it? perl is pretty new to me though I ppl say it''s just like php. is there any more optimal way to read thru the whole text and pick up what we want?


这篇关于过滤文件或字符串中的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆