---
title: "Ack Regular expression"
author: "夜鸣猪"
date: "2013-02-15T00:04:30Z"
tags: []
categories: ["编程语言"]
slug: "ack-regular-expression"
draft: false
lastmod: "2013-02-15T00:04:30Z"
id: 1798131
url: "https://hlee.iteye.com/blog/1798131"
---

ack uses Perl regular expressions, and those allow lookahead assertions:


```java
^(?!.*bar).*foo.*$
```

will match a line that contains foo but doesn't contain bar.

I'm not familiar with the usage of ack, but something like this should work:


```java
ack '^(?!.*bar).*foo.*$' myfile
```