troubleshooting Question

need help understanding REGEXP_REPLACE in Oracle

Avatar of Wm Peck 1958
Wm Peck 1958Flag for United States of America asked on
Oracle DatabaseRegular ExpressionsSQL
18 Comments2 Solutions435 ViewsLast Modified:
I've been slowing letting REGEXP in Oracle sink in, from several recent and helpful EE posts.

For these two examples, they seem to me like they do the same but there are exact opposite results:

for 'SMI$TH' this
SELECT REGEXP_REPLACE(UPPER('&cust_last_name') , '[^A-Za-z]', '') AS v_cust_last_name FROM dual;
returns 'SMITH'
- doesn't this mean: "Starting at the beginning of the string (^), find any characters in A-Z or a-z and replace it with nothing." Which would mean result = $, but obviously it's the OPPOSITE of that.

for 'SMI$TH' this
SELECT REGEXP_REPLACE(UPPER('&cust_last_name') , '[[:alpha:]]', '') AS v_cust_last_name FROM dual;
returns $
- this means to me: "Find any alpha in  the string and replace it with nothing". And so it does.

so I must be missing the proper interpretation of the first example . . .
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 18 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 18 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros