Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select alphanumeric characters using regex

I am fairly new to regexp_substr in oracle. I want extract just alphanumeric character from the string below. I have used below query but it doesn't seems to be working as expected.

select 
    regexp_substr('Save up to 10% on National Brands and 20% on Quill Brand Laser Toner','[[:alnum:]]+') string 
from dual;

I want the output to be look like this

Save up to 10 on National Brands and 20 on Quill Brand Laser Toner

or

Saveupto10onNationalBrandsand20onQuillBrandLaserToner

Thanks in advance. :)

like image 690
MJ03 Avatar asked Jan 24 '26 00:01

MJ03


1 Answers

I think you're looking for regexp_replace

select 
    regexp_replace('Save up to 10% on National Brands and 20% on Quill Brand Laser Toner',
                 '[^[:alnum:]]', '') string from dual;

SQL Fiddle

like image 69
benji Avatar answered Jan 26 '26 15:01

benji



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!