Reputation: 35
I have been trying to find the records which are non printable (i.e between ASCII 32 to 127), below i have mentioned the as per the query it should print all records with chr either less than 32 or more then 127 but it does not show the records with chr(160), while it do show the records with chr(10)
select regexp_instr(a.COL, '[^[:print:]]$') as STRING_POSITION,
a.COL, dump(col)
from tq84_compare a
where regexp_instr(a.COL, '[^[:print:]]') > 0;
insert into tq84_compare
values (11, chr(10));
insert into tq84_compare
values (11, chr(160));
insert into tq84_compare values (101,'On-line'||chr(160)||chr(160)||chr(160));
Upvotes: 1
Views: 144
Reputation: 626835
You cannot match Unicode hard space with [:space:]
, nor [^[:print:]]
, nor \s
patterns.
You may trim the strings with the following solution:
select regexp_replace(' some stuff ', '^[[:space:] ]+|[[:space:] ]+$', '') as result from dual
where the space inside is a hard space. The ^[[:space:] ]+
will match all ASCII whitespace and/or hard spaces at the start of the string and [[:space:] ]+$
will match all ASCII whitespace chars and a hard space at the end of the string.
If you want to add a hard space to your [^[:print:]]
, you need to use an alternation:
select regexp_replace(' some stuff ', '^([^[:print:]]| )+|([^[:print:]]| )+$', '') as result from dual
See this online demo.
Upvotes: 1