Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clickhouse query use regular expression

I know clickhouse provides replaceRegexpOne() function, but I want to use a regular expression to query, not replace. Like MySQL:

select username 
from table 
where username  REGEXP '^[0-9]*$'.

Hope you can help me, Thanks.

like image 903
XiaXiaoHai Avatar asked May 18 '26 18:05

XiaXiaoHai


1 Answers

Since 2023 the OP example works as well: username REGEXP '^[0-9]*$' is valid clickhouse sql.

There's match(haystack, pattern) function

Checks whether the string matches the pattern regular expression. A re2 regular expression. The syntax of the re2 regular expressions is more limited than the syntax of the Perl regular expressions.

Use as:

WHERE match(column, 'pattern')
-- or
WHERE column REGEXP 'pattern'

https://clickhouse.com/docs/sql-reference/functions/string-search-functions#match


To match groups use extract / extractAll functions

like image 122
simPod Avatar answered May 21 '26 13:05

simPod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!