I wanted to remove any character before ( in snowflake. For example: If the data has "Hello(World)", I want only "(World)".
Using SUBSTR and CHARINDEX functions:
SUBSTR
CHARINDEX
CREATE TABLE tab AS SELECT 'Hello(World)' AS col; SELECT SUBSTR(col, CHARINDEX('(', col)) FROM tab; -- (World)
You can use the regexp_substr function to extract text and use a greedy expression:
set str = 'Hello (world)'; select regexp_substr($str, '\\((.+)\\)');
I'm a big fan of SPLIT and SPLIT_PART
SPLIT
SPLIT_PART
CREATE TABLE tab AS SELECT 'Hello(World)' AS col; SELECT '(' || SPLIT_PART(col, '(', 2) FROM tab; -- (World)
Using
SUBSTRandCHARINDEXfunctions: