Regex to check if a string only has spaces

I want a regex to check if a string only has spaces.

Example: ""

I am using this regex

[/^ *$/]

      

But it also detects a line that has words in it.

Example: "abc xyz"

I want to use this regex in postgresql function like following

IF r.colmn IS NULL  OR CAST(r.colmn as text) = '' 
       OR CAST(r.colmn as text) ~ '[/^ *$/]' -- regex not working
THEN
     RAISE NOTICE 'Do something';       
END IF;

      

Is there any regex I can use in a postgresql function that only checks a string with spaces?

+3


source to share


1 answer


You need to remove [/

and /]

from your regex:



IF r.colmn IS NULL  OR CAST(r.colmn as text) = '' 
       OR CAST(r.colmn as text) ~ '^ *$' -- regex not working
THEN
     RAISE NOTICE 'Do something';       
END IF;

      

+2


source







All Articles