I'm trying to get an output where it has the string access
in it and has space on either side. Using ILIKE '% access %'
isn't working as I'm getting result with 'accessibility
in it.
Tried ILIKE '% access %'
.
Try this:
WITH
s(s) AS (
SELECT 'any ACCESS any'
)
SELECT
s
, REGEXP_LIKE(s,'^.* ACCESS .*$') AS is_rx_like
FROM s
-- out s | is_rx_like
-- out ----------------+------------
-- out any ACCESS any | true
An equivalent to LIKE '%[^az]ACCESS[^az]%'
in Snowflake would be using the REGEXP_LIKE
function to match the pattern.
Match On
- any string that contains the word "
ACCESS
" with a space before and after it- use the regular expression
.*[[:space:]](?i)ACCESS[[:space:]].*
- for any characters (
.
)- zero or more times (
*
)- flag that makes the search case-insensitive
(?i)
- before and after the word "
ACCESS
" (ie([[:space:]](?i)ACCESS[[:space:]])
)- may or may not have space
WHERE REGEXP_LIKE(column_name, '.*[[:space:]](?i)ACCESS[[:space:]].*')
Furthermore, can also useTRIM()
function to remove leading and trailing spaces before the comparison.
WHERE REGEXP_LIKE(TRIM(column_name), '.* (?i)ACCESS .*')
You could try using \b which means word boundary, along with 'i' parameter for case insensitive. This gracefully handles the beginning/end of text.
You can tinker with ACCESS vs access and adding/removing the 'i' parameter.
WITH CTE(COL) AS ( SELECT 'any ACCESS any' union all select 'Access blah blah'union all select ' blah blah Access' union all select 'Access'
union all SELECT 'any apple any' union all select 'apple blah blah'union all select ' blah blah apple' union all select 'apple' union all select 'accessibility')
SELECT
COL
, REGEXP_LIKE(COL,'^.* ACCESS .*$' ) MARCOTHESANE
, REGEXP_LIKE(TRIM(COL),'.* ACCESS .*') BITCOUB
, REGEXP_LIKE(COL,'.*(\\bACCESS\\b).*','i') ALT_ANSWER
FROM CTE;
Thank you for help everyone, This Worked for me'. [^az]ACCESS[^az]. ','i')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.