cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

i need a regex to get whole word with parentheses

183530
New Contributor III

SELECT '(CC) ABC' REGEXP '\\b\\(CC\\)\\b' AS TEST1,

    'A(CC) ABC' REGEXP '\\b\\(CC\\)\\b' AS TEST2,

    'A (CC)A ABC' REGEXP '\\b\\(CC\\)\\b' AS TEST3,

    'A (CC) A ABC' REGEXP '\\b\\(CC\\)\\b' AS TEST4,

    'A ABC (CC)' REGEXP '\\b\\(CC\\)\\b' AS TEST5

expected result:

TEST1 = TRUE

TEST2 = FALSE

TEST3 = FALSE

TEST4 = TRUE

TEST5 = TRUE

2 REPLIES 2

Hubert-Dudek
Esteemed Contributor III

Please share the expected output and what is condition for True and False.

183530
New Contributor III

get whole word "(CC)"

I had already written the output

expected outuput

 '(CC) ABC' REGEXP <<regex>> = TRUE

'A(CC) ABC' REGEXP <<regex>> = FALSE

'A (CC)A ABC' REGEXP <<regex>> = FALSE

 'A (CC) A ABC' REGEXP <<regex>> = TRUE

 'A ABC (CC)' REGEXP <<regex>> = TRUE