Link to home
Start Free TrialLog in
Avatar of Geoff Millikan
Geoff MillikanFlag for United States of America

asked on

Regex to strip everything but alphabet characters

What's the REGEX to identify all the alphabetic characters out of a string.  For example:
"1abc def2efg4" => "abcdefghij"

Open in new window

I'm testing in Oracle like this but it's just the normal REGEX I'm after.
SELECT regexp_substr('1abc def2ghij4','[A-Za-z]+') from dual

Open in new window

Thanks,

T1 Shopper

Avatar of rstjean
rstjean
Flag of Canada image

SELECT regexp_replace('1abc def2ghij4','[^A-Z^a-z]+','') from dual
If you want to keep them separated, simply take off the '+' at the end:

Regex: '[A-Za-z]'

This will return the letters individually.  With the + in there it grabs at least one and will grab as many that are in order as it sees.

Hope this helps.
Avatar of Marco Gasi
What's wrong with your regex?

Have you tried

SELECT regexp_substr('1abc def2ghij4','[^\d]') from dual

This works but doesn't trim result. Which prog language are you using?

Cheers
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What the pattern says is to match any character NOT ( [^] ) an uppercase ( A-Z ) or lowercase ( a-z ) letter. Since you are replacing those matched characters with empty string, the effect is to return a string of only letters.

   
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Geoff Millikan

ASKER

Awesome!  Thanks!  (PS.  I've been informed that thankfully there will be no regex in heaven.)
NP. Glad to help  :)