Reputation: 369
Using owa_pattern.change in oracle 9i.
Is it possible to remove a number and the trailing special character (pls note only the trailing) special character in a string?
I refer to special character as characters that is neither a word nor a number. e.g _ , # , @ ,$ etc ...
For example.
String = TEST_STRING_10
desired output would be TEST_STRING (notice only the trailing special character _ was removed).
I have already figured out how to remove the number but is stuck in the special character part.
I have this code so far.
OWA_PATTERN.CHANGE (string, '\d', '', 'g');
Appreciate any inputs.
Thanks!
Upvotes: 0
Views: 812
Reputation: 70732
Try the following.
OWA_PATTERN.CHANGE (string, '[^a-zA-Z]+$', '');
Regular expression
[^a-zA-Z]+ any character except: 'a' to 'z', 'A' to 'Z'
(1 or more times (matching the most amount possible))
$ before an optional \n, and the end of the string
Upvotes: 1
Reputation: 98921
This will do it:
DECLARE
result VARCHAR2(255);
BEGIN
string := 'TEST_STRING_10';
result := REGEXP_REPLACE(string, '([[:alnum:]_].*)_[[:digit:]]+', '\1', 1, 0, 'c');
END;
Upvotes: 0