Solved

Using oracle's Regexp to return fields that are alphanumeric only

Posted on 2011-03-19
6
860 Views
Last Modified: 2012-05-11
Hello,

I am having a poblem using regexp to return rows where the searched column has alphanumeric data.  It must contain a mix of characters and numbers and NOT only alpha characters and NOT only digits. So for example, a table with the column last_name contains

LAST_NAME
Brown
Ja2k
1Long
12345

I want the search to return rows with Ja2k and 1Long because it has a mix of digits and alphas in any occurance.  All alphas and all digits are rejected

The following does not work as required:

select * from tablea
where regexp_like(last_name, '^[[:alnum:]].+[[:alpha:]]*$' )
0
Comment
Question by:klyles95
  • 3
  • 2
6 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 total points
ID: 35173150
Try:
Regexp_like(last_name,'([0-9]+[A-Za-z]+[a-zA-Z0-9]*)|([a-zA-Z]+[0-9]+[a-zA-Z0-9]*)
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 35173503
same idea, slightly simplified

Regexp_like(last_name,'([0-9]+[A-Za-z]+|[a-zA-Z]+[0-9]+)[a-zA-Z0-9]*')
0
 

Author Closing Comment

by:klyles95
ID: 35173857
Thank you slightwv.  Worked like a charm
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 73

Expert Comment

by:sdstuber
ID: 35173967
already closed but even simpler...


Regexp_like(last_name,'([0-9]+[A-Za-z]|[a-zA-Z]+[0-9])[a-zA-Z0-9]*')
0
 

Author Comment

by:klyles95
ID: 35182228
Thank you sdstuber.  This works too!
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 35182593
actually,  all of the above are incorrect

they will all give a false positive for strings like this...

'12a!bc~34*xyz'

try this instead...

REGEXP_LIKE(last_name, '^([0-9]+[A-Za-z]|[a-zA-Z]+[0-9])[a-zA-Z0-9]*$')


you could add ^ and $ to the others as well
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now