[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Regex to strip everything but alphabet characters

Posted on 2010-09-23
8
Medium Priority
?
786 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:Geoff Millikan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Expert Comment

by:rstjean
ID: 33749455
SELECT regexp_replace('1abc def2ghij4','[^A-Z^a-z]+','') from dual
0
 
LVL 2

Expert Comment

by:Jcouls29
ID: 33749464
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.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33751075
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 800 total points
ID: 33753137
If you only want to see the alphabetic characters, then rstjean's pattern would be the way to go--just remove the ^ from the middle. With the second ^ in his/her pattern, your query would also return any ^ within the string.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 33753170
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.

   
0
 
LVL 4

Accepted Solution

by:
rstjean earned 1200 total points
ID: 33753428
marqusG:
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?

The problem with the original regex is that with the substr it will only return up to a space.

Your regex doesn't work either.  As substr returns only a small part of the string.  To return all of the matches as 1 string you need to replace everything that is not a letter with nothing by using replace.

@kaufmed:
Removing the second ^ is correct.   It was a sneaky little bugger that jumped in there.
SELECT regexp_replace('1abc def2^ghij4','[^A-Za-z]+','') from dual
0
 

Author Closing Comment

by:Geoff Millikan
ID: 33755659
Awesome!  Thanks!  (PS.  I've been informed that thankfully there will be no regex in heaven.)
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 33756141
NP. Glad to help  :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question