using match('hello', '\\b\\w+\\b') clickhouse function does returns "none", what Im…
- User
using match('hello', '\b\w+\b') clickhouse function does returns "none", what Im doing wrong?
- Assistant
using match('hello', '\b\w+\b') clickhouse function does returns "none", what Im doing wrong?
The issue you're encountering stems from the use of the \b (word boundary) metacharacter in your regular expression. ClickHouse utilizes the RE2 regular expression engine, which does not support the \b word boundary. As a result, your pattern \\b\\w+\\b fails to match the string 'hello', leading to the "none" result.
Regex Engine Limitation:
\b word boundary.Pattern Analysis:
\\b\\w+\\b
\\b represents \b in the regex pattern (escaped in the string literal).\\w+ represents \w+, which matches one or more word characters.\b isn't supported, the entire pattern fails to match.To achieve the desired matching without using \b, you can modify your regular expression to exclude the relying on word boundaries explicitly. Here's how:
Remove Word Boundaries:
\\w+ instead of \\b\\w+\\b.Alternative for Word Boundaries:
(^|[^a-zA-Z0-9_])\\w+([^a-zA-Z0-9_]|$)Here's how you can modify your query:
SELECT match('hello', '\\w+') AS result
Expected Result:
1
This returns 1, indicating a successful match of the word "hello".
\b word boundary in ClickHouse's match function with RE2 regex engine.\b from the regex pattern or use alternative patterns to define word boundaries.\\w+ instead of \\b\\w+\\b.By adjusting your regular expression to align with the capabilities of the RE2 engine, you should achieve the desired matching behavior in ClickHouse.
References:
Note: Always ensure that your regex patterns are compatible with the underlying engine to avoid unexpected results.
TL;DR: ClickHouse’s regex doesn’t support \b. Use a pattern without word boundaries, such as '\\w+', instead of '\\b\\w+\\b', to get matches like "hello".
Not yet included in a published release.