Geoff Millikan
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:
T1 Shopper
"1abc def2efg4" => "abcdefghij"
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
Thanks,T1 Shopper
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.
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.
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesome! Thanks! (PS. I've been informed that thankfully there will be no regex in heaven.)
NP. Glad to help :)