Need Regex pattern for right side of 10 digits from mobile Number

Viewed 16

I need help with how to write a regex for getting the last 10 digits from the right side of the mobile Number

For examples:

Input is: 919345678901 output is: 9345678901

input2 is: 09934567892 output is: 9934567892

2 Answers
regexp_replace(target,'^\d*(\d{10})$', '\1')

PL/SQL means Oracle; in that case, you don't need slow regular expressions as fast substr function does the job nicely:

Sample data:

SQL> with test (col) as
  2    (select '919345678901' from dual union all
  3     select '09934567892'  from dual
  4    )

Query begins here:

  5  select col,
  6         substr(col, -10) result
  7  from test;

COL          RESULT
------------ ----------------------------------------
919345678901 9345678901
09934567892  9934567892

SQL>
Related