How to use regex replace to ignore country code if it exists, I tried to use
select REGEXP_REPLACE(phone_number,'^/(?:011.44.)([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})$',
'\1-\2-\3') regex_output
from employees;
but it doesn't work,
the next one works for the format 515.123.4567
'([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})$'
but they have some phone numbers like 011.44.1345.729268 and I want to ignore 011.44 if exists at the beginning of numbers using one regex syntax if possible.
This is supposed to be the ignore syntax but its not working ^/(?:011.44.) or ^/(?!011.44.) I also tried ^/(?!([[:digit:]]{3})\.([[:digit:]]{2})\.) again doesn't work
Note I can do it using other functions, this question related to regex only
and I am using oracle HR database
--------------------------------------------------
| original numbers | expected output |
--------------------------------------------------
| phone_number | regex_output |
--------------------------------------------------
| 515.123.4567 | 515-123-4567 |
| 515.123.4567 | 515-123-4567 |
| 515.123.4567 | 515-123-4567 |
| 515.123.4567 | 515-123-4567 |
| 011.44.1345.729268 | 134-572-9268 |
| 011.44.1345.729268 | 134-572-9268 |
| 011.44.1345.729268 | 134-572-9268 |
| 011.44.1345.729268 | 134-572-9268 |
--------------------------------------------------
Update:
If anyone else is wondering I found out that in oracle non capturing groups are not supported
(?:...), non-capturing groups, are not supported, you should replace them with capturing groups. (Note that (:? is not a non-capturing group, it is just an optional colon at the start of the second capturing group in the pattern). -- Wiktor Stribiżew