有人可以帮我简化正则表达式吗?
我想 grep HTTP 访问日志,但我无法编写有效的正则表达式。这是我现在使用的:
grep \/console access.log | grep -v .gif | grep -v .js |grep -v .css
我怎样才能缩短它?谢谢!
I want to grep a HTTP access log, but I'm not able to write an efficient regular expression. Here is what I use now:
grep \/console access.log | grep -v .gif | grep -v .js |grep -v .css
How can I shorten it? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
grep 不支持前瞻,因此您仍然需要有两个实例:
对于负前瞻,较小但不一定更具可读性的正则表达式将是
grep does not support lookahead, so you'll still have to have two instances:
With negative lookahead, a smaller, although not necessarily more readable regexp would be
这可能感觉更简单,也可能不更简单。
This may or may not feel simpler.