返回正则表达式的每个实例
我进行了广泛的谷歌搜索,每个人都在告诉我如何返回正则表达式匹配的行...
让我们说我在文本文件中有这样的行:
<a href=http://google.com> Google </a>
我希望能够仅返回&gt;之间发生的内容且< (“谷歌”)。问题是我可能有一个包含数千行的文件,而我只想让 sed/awk 返回与正则表达式匹配的确切字符串。
我认为这将是类似的事情:
sed 's/>.*</p'
但显然这不会起作用...
它杀了我,因为我确信它可能非常简单,但我只是找不到正确的 sed 行。 sed 可以不这样做吗?
所以我只是希望它搜索一个文件,匹配我给它的正则表达式,并返回完全匹配(不是行)
任何人有任何想法吗?
I've extensively googled and everyone keeps telling me how to return the LINE that the regex matches...
go lets say that i have a line like this in a text file:
<a href=http://google.com> Google </a>
I want to be able to return ONLY what occurs between > and < ("Google"). The problem is that I could have a file with thousands of lines like that and I only want to have sed/awk return the EXACT string that matches the regex.
I figured it would be something along the lines of :
sed 's/>.*</p'
but obviously that wont work...
Its killing me because im sure its probably very simple but i just cant find the right sed line. can sed just not do it?
So I just want it to search through a file, match the regex i give it, and return the exact match (not the line)
anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与`sed
With `sed
如果您有 GNU grep,则
-o
选项可以满足您的需求。返回
这假设您的 html 标签及其包含的数据位于一行。这不匹配
If you have GNU grep, the
-o
option does what you want.returns
This assumes your html tags and their enclosed data are on one line. This would not match