How to REGEXP_REPLACE special character

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 14:55:23

问题


I am having issue with following regex

select REGEXP_REPLACE(declinereasondesc, '(.+)(£)(\d+)', '\1\3 (GBP)') as r from DECLINEREASON t

it does not match following rows

Too expensive : By less than £100
Too expensive : By more than £200

Expected outcome

Too expensive : By less than 100 (GBP)
Too expensive : By more than 200 (GBP)

EDIT:

screenshot for non-believers


回答1:


Figured it out myself problem is £ as I am sure everyone suspected

Solution contains two steps first is to get symbol code, even if you copy paste £ into select ascii() from dual it does not fly. You have to select the symbol like following to get correct code.

select ascii(substr(declinereasondesc, 30,1)) from DECLINEREASON t
where declinereasonid = 7;

In my case it gave 49827

then

select REGEXP_REPLACE(declinereasondesc, '(.+)('||chr(49827)||')(\d+)', '\1\3 (GBP)') from DECLINEREASON t;

and only then it works.



来源:https://stackoverflow.com/questions/27016064/how-to-regexp-replace-special-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!