@Test
  public void testSuccessfulComplexRegexMatch() {
    StreamRule rule = getSampleRule();
    rule.setField("some_field");
    rule.setValue("foo=^foo|bar\\d.+wat");

    Message msg = getSampleMessage();
    msg.addField("some_field", "bar1foowat");

    StreamRuleMatcher matcher = getMatcher(rule);
    assertTrue(matcher.match(msg, rule));
  }
  @POST
  @Path("/{streamRuleId}")
  @Timed
  @ApiOperation(value = "Update a stream rule")
  @ApiResponses(
      value = {
        @ApiResponse(code = 404, message = "Stream or stream rule not found."),
        @ApiResponse(code = 400, message = "Invalid JSON Body.")
      })
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response update(
      @ApiParam(
              title = "streamid",
              description = "The stream id this rule belongs to.",
              required = true)
          @PathParam("streamid")
          String streamid,
      @ApiParam(
              title = "streamRuleId",
              description = "The stream rule id we are updating",
              required = true)
          @PathParam("streamRuleId")
          String streamRuleId,
      @ApiParam(title = "JSON body", required = true) String body) {
    CreateRequest cr;
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);

    try {
      cr = objectMapper.readValue(body, CreateRequest.class);
    } catch (IOException e) {
      LOG.error("Error while parsing JSON", e);
      throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
    }

    StreamRule streamRule;
    try {
      streamRule = streamRuleService.load(loadObjectId(streamRuleId));
      if (!streamRule.getStreamId().equals(streamid)) {
        throw new NotFoundException();
      }
    } catch (org.graylog2.database.NotFoundException e) {
      throw new WebApplicationException(404);
    }

    streamRule.setField(cr.field);
    streamRule.setType(StreamRuleType.fromInteger(cr.type));
    streamRule.setInverted(cr.inverted);
    streamRule.setValue(cr.value);

    String id;
    try {
      streamRuleService.save(streamRule);
      id = streamRule.getId();
    } catch (ValidationException e) {
      LOG.error("Validation error.", e);
      throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
    }

    Map<String, Object> result = Maps.newHashMap();
    result.put("streamrule_id", id);

    return Response.status(Response.Status.OK).entity(json(result)).build();
  }