I have a string that i would like to convert from a sequence of strings to a sequence of strings separated by a hyphen. Example
200400116828 --> 2004-001168-28
For String to be converted, the input string must follow these rules:
- Starts with a 1 or 2
- Followed by three digits
- Followed by 6 digits
- Followed by 2 digits
I use a Regex to extract the above groups from the input string to build the output string using the Regex '^([12]\d{3})(\d{6})(\d{2})$'
I managed to get it to work using the following query:
Select REGEXP_REPLACE(
'200400116828','^([12]\d{3})(\d{6})(\d{2})$','\1-\2-\3'
) from dual;
Output - 2004-001168-28
But i am confused by the following query also works but with a wrong output:
Select REGEXP_REPLACE(
'200400116828','^([12]\d{3})(\d{6})(\d{2})$','\10-\11-\12'
) from dual;
Output - 20040-20041-20042
Could somebody please explain the output of the 2nd query because to me it does not match the RegEx provide.
\10is treated as\1followed by a0