Perhaps a clearer test would be to generate some strings containing various whitespace characters and then use case
expressions to see whether they match different regexes.
with demo (str) as
( select ':' from dual union all
select 'a' from dual union all
select 'b' from dual union all
select 'c' from dual union all
select 'contains'||chr(9)||'tabs' from dual union all
select 'contains'||chr(10)||chr(13)||'linebreaks' from dual union all
select 'contains some spaces' from dual
)
select str
, case when regexp_like(str,'[:blank:]') then 'Y' end as "[:blank:]"
, case when regexp_like(str,'[[:blank:]]') then 'Y' end as "[[:blank:]]"
, case when regexp_like(str,'[[:space:]]') then 'Y' end as "[[:space:]]"
, case when regexp_like(str,'\s') then 'Y' end as "\s"
from demo
order by 1;
STR [:blank:] [[:blank:]] [[:space:]] \s
-------------------- --------- ----------- ----------- --
: Y
a Y
b Y
c
contains tabs Y Y Y
contains Y Y Y
linebreaks
contains some spaces Y Y Y Y
(I manually edited the result for the row with tabs to align the results, otherwise the tab messes it up and makes it harder to read.)
[:blank:]
matches any of :
, b
, l
, a
, n
, k
, because a character class is only valid within a []
bracket expression.
[[:blank:]]
only matches spaces.
[[:space:]]
matches tab, newline, carriage return and space.
\s
is the same as [[:space:]]
As for your example, it is not behaving as you expected in two different ways.
Firstly, [^[[:blank:]]]
should be [^[:blank:]]
- that is, the character class [:blank:]
within a bracketed expression.
Secondly, the corrected syntax still returns a match when there are no blanks because it looks for any character that is not a space, for example the first character G
is not a space so it matches the expression:
regexp_like('Greg94/Eric99Chandler/Faulkner','[^ ]');
To identify strings that do not contain any whitespace character, you should use:
not regexp_like(str,'\s')
or
not regexp_like(str, '[[:space:]]')