Reputation: 35557
In Oracle 11g, I need to check perform a check to see if the following format is true (i.e. via a regular expression):
PaaaaE0%
PaaaaD2%
where this value is of the following format:
P ( followed by any 4 alphanumeric digits) E or D (followed by atleast 1 numeric digit)
As part of the 4 alphanumeric digits, if alpha then they need to be uppercase.
For now, I have tried something like:
REGEXP_LIKE('PWOOOE12s3','[P][:alnum:]{4}[ED][:digit:]{1}')
Upvotes: 1
Views: 2879
Reputation: 10648
You're pretty close:
[[:digit:]]
. Note the outer braces for a matching list.{n}
matches exactly n
occurences, use +
to match one or more occurences.[:upper:]
matches uppercase letters, matching list [[:upper:]|[:digit:]]
matches any uppercase letter or digit.^
anchor to match only from the beginning of the string. You can left it out if it doesn't fit your purpose.This should get the job done:
SQL@xe> !cat so40.sql
with
data_ as (
select 1 id, 'PWOOOE12s3' str from dual union
select 2 id, 'PwoooE12s3' str from dual
)
select id, str from data_
where regexp_like(str, '^P[[:upper:]|[:digit:]]{4}[ED][[:digit:]]+')
;
SQL@xe> @so40
ID STR
---------- ----------
1 PWOOOE12s3
SQL@xe>
Upvotes: 1