From 1bde0fda7ae8365d2a1e3f5fc9d5121030325217 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Thu, 21 Dec 2023 17:43:35 +0000 Subject: [PATCH] add for hogql here? --- posthog/hogql/property.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/posthog/hogql/property.py b/posthog/hogql/property.py index ce4ea3bdfe14f..e65fe204cd216 100644 --- a/posthog/hogql/property.py +++ b/posthog/hogql/property.py @@ -202,12 +202,18 @@ def property_to_expr( left=field, right=ast.Constant(value=f"%{value}%"), ) + # we follow re2 regex syntax and so does ClickHouse **except** + # For example, the string a\nb shouldn't match the pattern a.b, but it does in CH + # this is because According to the re2 docs, the s flag is false by default, + # but in CH it seems to be true by default. + # prepending (?-s) to the regex string will make it work as expected + # see https://github.com/ClickHouse/ClickHouse/issues/34603 elif operator == PropertyOperator.regex: - return ast.Call(name="match", args=[field, ast.Constant(value=value)]) + return ast.Call(name="match", args=[field, ast.Constant(value=f"(?-s){value}")]) elif operator == PropertyOperator.not_regex: return ast.Call( name="not", - args=[ast.Call(name="match", args=[field, ast.Constant(value=value)])], + args=[ast.Call(name="match", args=[field, ast.Constant(value=f"(?-s){value}")])], ) elif operator == PropertyOperator.exact or operator == PropertyOperator.is_date_exact: op = ast.CompareOperationOp.Eq