@Test
  public void regex() {
    final ObjectMapper mapper = new ObjectMapper().registerModule(new BsonModule());
    final CodecRegistry registry = JacksonCodecs.registryFromMapper(mapper);

    Consumer<Bson> validate = bson -> {
      BsonDocument doc = bson.toBsonDocument(BsonDocument.class, registry);
      check(doc.get("a")).is(new BsonRegularExpression("a.*b"));
    };

    validate.accept(Filters.eq("a", Pattern.compile("a.*b")));
    validate.accept(Filters.regex("a", Pattern.compile("a.*b")));
    validate.accept(Filters.regex("a", "a.*b"));
  }
Test that regular expression is correctly encoded
criteria/mongo/test/org/immutables/criteria/mongo/bson4jackson/JacksonCodecsTest.java