简体   繁体   中英

oracle regular expression issue

I have been trying to find the records which are non printable (ie 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));

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 .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM