Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreben committed Nov 29, 2016
1 parent 490d60a commit 188d7b2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,15 @@ which exposes a method `setExpression(Expression expr)` and implements the `Expr
import com.github.sgreben.regex_builder.ExpressionWrapper;
```

To use the class, simply extend it and call `setExpression` in your constructor or initialization block.
You can then pass it to any `regex-builder` method that expects an `Expression`.

### Reusable Apache log expression
Using `ExpressionWrapper`, we can package the Apache log
example above as follows:
```java
public class ApacheLog extends ExpressionWrapper {
public final CaptureGroup ip, client, user, dateTime, method, request, protocol, responseCode, size;
private final Expression expression;

{
Expression nonWhitespace = repeat1(CharClass.nonWhitespaceChar());
Expand All @@ -223,7 +225,7 @@ public class ApacheLog extends ExpressionWrapper {
responseCode = capture(repeat(CharClass.digit(), 3));
size = capture(repeat1(CharClass.digit()));

expression = sequence(
Expression expression = sequence(
ip, ' ', client, ' ', user, " [", dateTime, "] \"", method, ' ', request, ' ', protocol, "\" ", responseCode, ' ', size,
);
setExpression(expression);
Expand Down

0 comments on commit 188d7b2

Please sign in to comment.