I have values like this:
aaa_1, bb_5, c_21, a_b.
Now i need remove trailing underscore and numbers from this values. A_b (string_string) is valid value and need not to be removed. Basicaly, i need regexp patern to extract only trailing _[any number of digits] from string.
I am using Oracle 11gR2
Any suggestion?
You need to use REGEXP_REPLACE with the regex expression ‘\_[[:digit:]]{1,}’
This translates to find the (escaped) underscore with one or more digits after it:
e.g.
Returns
If you want to make sure you only remove the underscore and digits when there are no alpha characters then add the $ to the end of the regex string to signify the end of the string.
e.g. First with the “$” second without
Returns
Regular expressions can be awkward but this link is one of the easiest to understand that I have found for Oracle regex expressions:
http://www.dba-oracle.com/t_regular_expressions.htm
Hope this helps.