开发者

Can anybody help me to simplify a regex?

开发者 https://www.devze.com 2023-04-13 06:09 出处:网络
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:

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 .c开发者_C百科ss

How can I shorten it? Thanks!


grep does not support lookahead, so you'll still have to have two instances:

grep /console access.log | grep -v '\.\(gif|js|css\)'

With negative lookahead, a smaller, although not necessarily more readable regexp would be

^(?!.*?\.(gif|js|css)).*/console.*$


This may or may not feel simpler.

sed -r -n -e '/\.(js|css|gif)/d' -e '\%/console%p' access.log
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号